com_content에 comment 수를 보여준다고 하면,
먼저 함수를 만듭니다.
function cu_GetCommentCount($id, $component = 'com_content') { //this function gets a count of comments for the given content item $result = false; $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select('COUNT(id)'); $query->from('#__comment'); $query->where('component = '.$db->quote($component)); $query->where('contentid = '.$db->quote(intval($id))); $db->setQuery($query); $count = $db->loadResult(); if ($count !== false) { $result = intval($count); } return $result; }
Comment 수를 보여주고 싶은 곳에 다음 코드를 삽입합니다.
?php echo cu_GetCommentCount($article->id, 'com_content'); ?>
참조 사이트:
https://compojoom.com/forum/50-wishlist/17347-add-comments-count-next-to-article-title