I've wrote a hack to get the comments count working in News Show Pro with Jcomments integreated to k2.
in /modules/mod_news_pro_gk4/gk_classes/gk.source.k2.php
replace this function
- Code: Select all
function getComments($content, $config) {
//
$db =& JFactory::getDBO();
$counters_tab = array();
//
if(count($content) > 0) {
// initializing variables
$sql_where = '';
$ids = $content['ID'];
//
for($i = 0; $i < count($ids); $i++ ) {
// linking string with content IDs
$sql_where .= ($i != 0) ? ' OR content.id = '.$ids[$i] : ' content.id = '.$ids[$i];
}
// creating SQL query
$query_news = '
SELECT
content.id AS id,
COUNT(comments.itemID) AS count
FROM
#__k2_items AS content
LEFT JOIN
#__k2_comments AS comments
ON comments.itemID = content.id
WHERE
comments.published
AND ( '.$sql_where.' )
GROUP BY
comments.itemID
;';
// run SQL query
$db->setQuery($query_news);
// when exist some results
if($counters = $db->loadObjectList()) {
// generating tables of news data
foreach($counters as $item) {
$counters_tab['art'.$item->id] = $item->count;
}
}
}
return $counters_tab;
}
with
- Code: Select all
function getComments($content, $config) {
//
$db =& JFactory::getDBO();
$counters_tab = array();
if(count($content) > 0) {
// initializing variables
$sql_where = '';
$ids = $content['ID'];
//
for($i = 0; $i < count($ids); $i++ ) {
// linking string with content IDs
$sql_where .= ($i != 0) ? ' OR content.id = '.$ids[$i] : ' content.id = '.$ids[$i];
}
// creating SQL query
$query_news = '
SELECT
content.id AS id
FROM
#__k2_items AS content
WHERE
( '.$sql_where.' )
;';
// run SQL query
$db->setQuery($query_news);
// when exist some results
if($counters = $db->loadObjectList()) {
$comments = JPATH_BASE . DS . 'components' . DS . 'com_jcomments' . DS . 'jcomments.php';
// generating tables of news data
if (file_exists($comments)) {
require_once($comments);
foreach($counters as $item) {
$item->count = JComments::getCommentsCount($item->id, 'com_k2');
$counters_tab['art'.$item->id] = $item->count;
}
}
else {
foreach($counters as $item) {
$counters_tab['art'.$item->id] = 0;
}
}
}
}
return $counters_tab;
}
tested with K2.4.1 + Jcomments 2.2 + K2 Jcomments plugin + News Show Pro g4