简体   繁体   English

如何 output 用户使用 JComments / Joomla 3 留下的评论量?

[英]How to output the amount of comments left by a user with JComments / Joomla 3?

JoomlaTune - developers of the JComments extension - offers the following code to display comments anywhere: JoomlaTune - JComments 扩展的开发者 - 提供以下代码以在任何地方显示评论:

    <?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.通过将文章的id代入$this->item->id就可以得到这篇文章的素材数量。

Is it possible to somehow adapt this code to display the number of comments left by specific users by his id.是否有可能以某种方式调整此代码以显示特定用户通过其 ID 留下的评论数量。 Or maybe this variable already exists somewhere in the component code?或者这个变量可能已经存在于组件代码的某个地方?

Thanks a lot in advance!提前非常感谢!

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM