0
votes

I really need help this time - Joomla 2.5 and latest K2. I'm using the default K2 comment system and I want to show the "Description" field for every commenter on that page. So far I have this code:

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

But this shows the description for the author of the page only. If I log in with another account, it'll also show my own Description as long as I'm logged in.

All the coding I'm doing is in /components/com_k2/templates/default/item.php

The whole code for comments looks like this:

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

1 Answers

0
votes

With Joomla 2.5 you can use that to get basic user information, but you want to use the following to get the "description" or "about me" content of the commenting user..

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

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

Here is the link as well, this might help if you would like to do other things with the JUserHelper..

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

EDIT: Make sure the plugin "User - Profile" is enabled or this will not work.