By Niccolo Angeli on Saturday, 14 July 2018
Posted in Technical Issues
Replies 1
Likes 0
Views 1.1K
Votes 0
Hello,
I have a custom article template and I want to display the number of comments and the total rating right after the article title.

I have added this code in my custom template here /test/templates/rt_galatea/html/com_content/article


<!-- Render Komento rating on single article page -->
<?php
// call Komento comment model
$commentsModel = KT::model('Comments');

// Retrieve total rating for this particular article post (single article page)
$ratings = $commentsModel->getOverallRatings('com_content', $this->item->id);

if ($ratings) {
$totalRating = $ratings->value;
$totalRatingCount = $ratings->total;
}
?>



<div id="kt">
<h3 class="kt-title-bar__title">
<?php echo JText::_('COM_KOMENTO_COMMENTS'); ?> (<span class="commentCounter" data-kt-counter><?php echo $commentCount; ?></span>)
</h3>
<div class="kt-ratings-overview" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
<div class="kt-ratings-stars" data-kt-ratings-overall data-score="<?php echo $totalRating / 2; ?>"></div>

<span class="kt-ratings-title"><?php echo JText::sprintf('COM_KOMENTO_RATING_OVERVIEW_TOTAL', $totalRating / 2, 5, $totalRatingCount);?></span>

<meta itemprop="ratingValue" content="<?php echo $totalRating / 2;?>" />
<meta itemprop="reviewCount" content="<?php echo $totalRatingCount;?>" />
<meta itemprop="bestRating" content="5" />
<meta itemprop="worstRating" content="0" />
</div>
</div>
<!-- Render Komento rating on single article page - end -->


but this part of the code is not working

<h3 class="kt-title-bar__title">
<?php echo JText::_('COM_KOMENTO_COMMENTS'); ?> (<span class="commentCounter" data-kt-counter><?php echo $commentCount; ?></span>)
</h3>

it should show "comments (0)" when there are no comments, but it just shows "comments ()"
I inserted a test comment and it still shows "comments ()"

I understand that the code I insrted is probably not retrieving the total number of comments, in fact
the same code above the normal komento comment form is working fine and shows "comments (0)" or "comments (1)"
(see screenshot komento_2)

could you teel me how to fix this?
thank you
The variable $commentCount probably does not exist in that context. You would need to run the necessary queries to get the comment count,

[gist]
$commentsModel = KT::model('Comments');
$commentCount = $commentsModel->getCount('com_content', $this->item->id);
[/gist]
·
Sunday, 15 July 2018 12:39
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post