0

这次我真的需要帮助 - Joomla 2.5 和最新的 K2。我正在使用默认的 K2 评论系统,我想为该页面上的每个评论者显示“描述”字段。到目前为止,我有这个代码:

$thisUserdata =& JFactory::getUser($comment->userID);
echo $thisUserdata->profile->description;

但这仅显示页面作者的描述。如果我使用其他帐户登录,只要我登录,它也会显示我自己的描述。

我正在做的所有编码都在 /components/com_k2/templates/default/item.php

注释的整个代码如下所示:

<?php if($this->item->numOfComments>0 && $this->item->params->get('itemComments') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2'))): ?>
    <!-- Item user comments -->
      <ul>
        <?php foreach ($this->item->comments as $key=>$comment): ?>
        <li class="<?php echo ($key%2) ? "odd" : "even"; echo (!$this->item->created_by_alias && $comment->userID==$this->item->created_by) ? " author-comment" : ""; echo($comment->published) ? '':' unpublishedComment'; ?>">
            <div class="avatar">
                <?php if($comment->userImage): ?>
                <a href="<?php echo JFilterOutput::cleanText($comment->userLink); ?>" target="_blank" rel="nofollow">
                    <img src="<?php echo $comment->userImage; ?>" alt="<?php echo JFilterOutput::cleanText($comment->userName); ?>" width="<?php echo $this->item->params->get('commenterImgWidth'); ?>" />
                </a>
                <?php endif; ?>
            </div>
            <div class="inner">
                <div class="author">
                    <?php if(!empty($comment->userLink)): ?>
                        <a href="<?php echo $comment->userLink; ?>" title="View <?php echo $comment->userName; ?> profile" target="_blank" rel="nofollow">
                            <?php echo $comment->userName; ?>
                        </a>
                    <?php else: ?>
                        <a rel="nofollow"><?php echo $comment->userName; ?></a>
                    <?php endif; ?>
                </div>
                <div class="date">
                    &#160;<?php echo JHTML::_('date', $comment->commentDate, JText::_('K2_DATE_FORMAT_COM_MARIO')); ?>
                </div>
                <p><?php echo $comment->commentText; ?>
                <?php
                // USER DESCRIPTION
                $thisUserdata =& JFactory::getUser($comment->userID);
                echo $thisUserdata->profile->description;
                ?>          
                </div>
            </div>
        </li>
        <?php endforeach; ?>
      </ul>

      <div class="itemCommentsPagination">
        <?php echo $this->pagination->getPagesLinks(); ?>
        <div class="clr"></div>
      </div>
<?php endif; ?>

<?php if($this->item->params->get('commentsFormPosition')=='below' && $this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($this->item->catid)))): ?>
    <!-- Item comments form -->
    <div class="itemCommentsForm">
        <?php echo $this->loadTemplate('comments_form'); ?>
    </div>
<?php endif; ?>
4

1 回答 1

0

使用 Joomla 2.5,您可以使用它来获取基本用户信息,但您想使用以下内容来获取评论用户的“描述”或“关于我”的内容。

$commentUser = JUserHelper::getProfile($comment->userID);
print_r($commentUser);

$about_me = $commentUser->profile['aboutme'];
echo $about_me;

这也是链接,如果您想使用 JUserHelper 做其他事情,这可能会有所帮助。

http://api.joomla.org/Joomla-Platform/User/JUserHelper.html#getProfile

编辑:确保启用插件“用户 - 个人资料”,否则这将不起作用。

于 2012-06-12T18:46:33.657 回答