0

JoomlaTune - developers of the JComments extension - offers the following code to display comments anywhere:

    <?php
            $comments = JPATH_SITE . '/components/com_jcomments/jcomments.php';
                if (file_exists($comments)) {
                require_once($comments);
                $options = array();
                $options['object_id'] = $this->item->id;
                $options['object_group'] = 'com_content';
                $options['published'] = 1;
                $count = JCommentsModel::getCommentsCount($options);
                echo ('<span>'. $count .'</span>');
            }
    ?>

by substituting the id of the article into $this->item->id you can get the number of materials for this article.

Is it possible to somehow adapt this code to display the number of comments left by specific users by his id. Or maybe this variable already exists somewhere in the component code?

Thanks a lot in advance!

2
  • I'm not really sure what I'm looking at, but a quick google search says there's a JComments::showComments function that you should be able to get all comments then loop through them to filter out comments from specific users?
    – Rager
    Commented Sep 20, 2022 at 23:34
  • Also you could dig through this github.com/ThomDietrich/jcomments I bet there's lots of good stuff to look at for potential additions.
    – Rager
    Commented Sep 20, 2022 at 23:37

1 Answer 1

0

all you need to do is add the following code:

use Joomla\CMS\Factory;
$user = Factory::getUser();
$options['userid'] = $user->id;

just before:

$count = JCommentsModel::getCommentsCount($options);
0

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