0

I'm trying to add komento comments count add to article at below file

templates/name-template/html/com_content/article/default.php

code

                    $query->select(' COUNT(jc.id) AS comments_count, MAX(jc.created) AS comments_date')
                    ->join('LEFT', '#__komento_comments AS jc ON jc.cid = a.id AND jc.component = \'com_content\' AND jc.published = 1');

and use this code for fetch

<?php echo $this->item->comments_count; ?>

but not show comments count ad get error

10
  • Please show us your efforts before posting your question. It is important that this community is not used as a free coding service. We don't mind pitching in if you are stuck, but if you need a professional developer that is another matter. Questions that require "hands-on professional development" are off-topic here. When you edit your question to show your best coding attempt and the reason that it failed to meet your expectations, please also bother to capitalize the word i so that nobody else will need to clean up your post. I upvote clear, on-topic questions that don't need editing. Jun 4, 2019 at 21:18
  • @mickmackusa thanks for help
    – user9530
    Jun 5, 2019 at 10:50
  • What is the error? Where is the from() call? $this->item doesn't fetch query results. Do you also need to extract the most recent date? Jun 5, 2019 at 11:05
  • Is $comments_link relevant to your question? If not, please remove it. Looks like you don't need a JOIN. Do you mean to use FROM instead? Jun 5, 2019 at 11:11
  • @mickmackusa $comment_link deleted from code ...i want get comment count related post from database and show at article
    – user9530
    Jun 5, 2019 at 11:45

1 Answer 1

1

If you are using Komento with Joomla, here is a code for counting the number of published comments related to an article:

// Context
$currentArticleId = $this->item->id;
$db = JFactory::getDbo();

// Build the query
$query = $db->getQuery(true);
$query->select('COUNT(*)');
$query->from($db->quoteName('#__komento_comments'));
$query->where($db->quoteName('cid') . ' = ' . $currentArticleId);
$query->andWhere($db->quoteName('published') . ' = 1');

// Get the result
$db->setQuery($query);
$comment_count = $db->loadResult();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.