[英]How to output the amount of comments left by a user with JComments / Joomla 3?
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>');
}
?>
通過將文章的id代入$this->item->id就可以得到這篇文章的素材數量。
是否有可能以某種方式調整此代碼以顯示特定用戶通過其 ID 留下的評論數量。 或者這個變量可能已經存在於組件代碼的某個地方?
提前非常感謝!
您需要做的就是添加以下代碼:
use Joomla\CMS\Factory;
$user = Factory::getUser();
$options['userid'] = $user->id;
就在之前:
$count = JCommentsModel::getCommentsCount($options);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.