I use JComments component at almost my sites which need a comments system. But I don`t like links like "Add comment" or "2 Comments" under each article intro. I like comments counter under article header, like in some EasyBlog, K2 article templates. So this post is about how to show JComments comments counter anywhere you want. Let`s start.

Before you must include main JComments php class. If it exists and true - use once where you want, for example in modules, plugins or article templates. Let`s include JComments class as $jcclass. 

 $jcclass = JPATH_SITE . '/components/com_jcomments/jcomments.php';
if (file_exists($jcclass)) :
require_once($jcclass);
$comcount = JComments::getCommentsCount($displayData['item']->id, 'com_content');
endif;

Now $comcount variable by using function getCommentsCount will get number of comments in Joomla article by it`s ID. Then to show number of comments you can use code:

 <?php echo ' ' . JTEXT::_('MY_COMMENTS'); echo $comcount;?>

You can set MY_COMMENTS Joomla language constant in Administration panel. It works on my blog and hope usefull for your`s. 

If you like this - share it with your friends. That would be the best "donation" for me!

If you want to ask question or comment - login by using your favourite social network

Comments  
Gabriele
# Gabriele 2019-10-19 21:39
Thanks for any other fantastic article. The place else may anybody get that type of info in such a perfect way
of writing? I have a presentation subsequent week, and I'm on the search for
such info.

Feel free to visit my webpage ... be-tours.it/r/dtgm85yj
Reply | Reply with quote | Quote
Add comment