Do you want to enhance beautiful CCK extension called
K2 and replace its standart comments functional on JComments?
Here is the instruction for
K2 v2.1 (build 20090909):
1. Open
components/com_k2/templates/item.php and remove next code from line 486 up to 560:
<?php if(
$this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2'))):?>
<!-- Item comments -->
<a name="itemCommentsAnchor" id="itemCommentsAnchor"></a>
<div class="itemComments">
<?php if($this->item->params->get('commentsFormPosition')=='above' && $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; ?>
<?php if($this->item->numOfComments>0 && $this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2'))): ?>
<!-- Item user comments -->
<h3 class="itemCommentsCounter">
<span><?php echo $this->item->numOfComments; ?></span> <?php echo ($this->item->numOfComments>1) ? JText::_('comments') : JText::_('comment'); ?>
</h3>
<ul class="itemCommentsList">
<?php foreach ($this->item->comments as $key=>$comment): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?>">
<span class="commentLink">
<a href="<?php echo $this->item->link; ?>#comment<?php echo $comment->id; ?>" name="comment<?php echo $comment->id; ?>" id="comment<?php echo $comment->id; ?>">
<?php echo JText::_('Comment Link'); ?>
</a>
</span>
<?php if($comment->userImage):?>
<img src="<?php echo $comment->userImage; ?>" alt="<?php echo $comment->userName; ?>" width="<?php echo $this->item->params->get('commenterImgWidth'); ?>" />
<?php endif; ?>
<span class="commentDate">
<?php echo JHTML::_('date', $comment->commentDate, JText::_('DATE_FORMAT_LC2')); ?>
</span>
<span class="commentAuthorName">
<?php echo JText::_("posted by"); ?>
<?php if(!empty($comment->userLink)): ?>
<a href="<?php echo $comment->userLink; ?>" title="<?php echo $comment->userName; ?>">
<?php echo $comment->userName; ?>
</a>
<?php else: ?>
<?php echo $comment->userName; ?>
<?php endif; ?>
</span>
<p><?php echo $comment->commentText; ?></p>
<span class="commentAuthorEmail">
<?php echo JHTML::_('Email.cloak', $comment->commentEmail, 0); ?>
</span>
<br class="clr" />
</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; ?>
</div>
<?php endif; ?>
And add next code instead of previous one:
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
$comments = JPATH_BASE . DS . 'components' . DS . 'com_jcomments' . DS . 'jcomments.php';
if (file_exists($comments)) {
require_once($comments);
?>
<a name="itemCommentsAnchor" id="itemCommentsAnchor"></a>
<?php
echo JComments::showComments($this->item->id, 'com_k2', $this->item->title);
}
?>
2. Open
components/com_k2/models/item.php (line 777 up to 785) file and replace:
function countItemComments($itemID){
$db = & JFactory::getDBO ();
$query="SELECT COUNT(*) FROM #__k2_comments WHERE published=1 AND itemID={$itemID}";
$db->setQuery($query);
$result = $db->loadResult();
return $result;
}
at:
function countItemComments($itemID){
$comments = JPATH_BASE . DS . 'components' . DS . 'com_jcomments' . DS . 'jcomments.php';
if (file_exists($comments)) {
require_once($comments);
return JComments::getCommentsCount($itemID, 'com_k2');
}
return 0;
}
3. If you use old version of JComments (2.0), then download enclosed archive, unpack it and extract com_k2.plugin.php file to
/components/com_jcomments/plugins/ directory. If you're using JComments 2.1 just skip this step.
Thanks to
smart and
Devil for this solution.