【问题标题】:Jooma K2 show user description in commentsJooma K2 在评论中显示用户描述
【发布时间】:2012-06-15 03:22:19
【问题描述】:

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

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

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

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

cmets 的整个代码如下所示:

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

【问题讨论】:

    标签: joomla joomla-k2


    【解决方案1】:

    使用 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

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

    【讨论】:

    • 您好,感谢您的帮助,但这是 joomla 打印的内容: JObject Object ( [_errors:protected] => Array ( ) [id] => 52 ) 如果我只是回显我得到的 $commentUser : JObject
    • 确保启用插件“用户 - 个人资料”。
    猜你喜欢
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 2017-04-08
    • 2013-04-13
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    相关资源
    最近更新 更多