By Mist on Thursday, 08 May 2014
Replies 3
Likes 0
Views 3.3K
Votes 0
Sometimes you need to display total blog post count "outside" EasyBlog component, in a custom template position.
You can do this by using the code below. The code will query the database and will display the total published blog posts count for current logged-in user.


<?php
$user =JFactory::getUser();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = 'select count(1) as `post_count`';
$query .= ' from `#__easyblog_post` as a';
$query .= ' where a.`created_by` = ' . $user->id;
$query .= ' and a.published = ' . $db->Quote('1');
$db->setQuery($query);
$postcount = $db->loadResult();
echo $postcount;
?>


You can use this if you want for example to present to the current logged-in user his total blog posts count. Think about it kinda like a "notification" count. In our case scenario, we built a "My Account" custom menu where we listed some personal menu option for current logged in user. We used the above code to show post count next to "My Blog Posts" menu option.

Enjoy ! I hope you will find a good use !
Hello Mist,

Thanks for the info! Really appreciate that. This might be very helpful for other users.
·
Thursday, 08 May 2014 10:21
·
0 Likes
·
0 Votes
·
0 Comments
·
Thank you!!!

I was looking for a way to show user's blog post on easysocial stats profile widget. This did the trick!

·
Thursday, 10 May 2018 07:43
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks for your feedback this suggestion code still worked.
·
Thursday, 10 May 2018 08:47
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post