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!


Or just buy me a beer :-)

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

Comments  

Reynaldo Permalink 0 Reynaldo
Heya i'm for the first time here. I found this board and I in finding It truly useful & it helped me out much.

I'm hoping to give something back and aid others such as you aided me.



Here is my web blog - Dewa
Poker88
2020-10-23 16:41 Reply Reply with quote Quote

Add comment

Answer a question:
What is the first letter in word Joomla?