[eluser]eokorie[/eluser]
How about counting the number of comments in the model?
I am going to assume you have a table for comments and another for the articles and both tables are linked by the article id.
This is what I use to display the number of comments ofr each individual post on my own blog:
Code:
$this->db->select('*');
$this->db->select("DATE_FORMAT(gk_blog_posts.date_art,'%W, %D %M %Y') AS article_date", FALSE );
$this->db->select("Count(gk_blog_comments.id_com) AS TotalComments");
// $this->db->from('gk_blog_posts');
($cat)? $this->db->where('idtop_art', $cat) : '' ;
$this->db->where('status_art','publish');
$this->db->join('gk_users', 'gk_users.id_usr = gk_blog_posts.author_art', 'left');
$this->db->join('gk_blog_comments', 'gk_blog_comments.idart_com = gk_blog_posts.id_art AND gk_blog_comments.is_approved = 1', 'left');
$this->db->join('gk_blog_categories', 'gk_blog_categories.id_top = gk_blog_posts.idtop_art', 'left');
$this->db->group_by('id_art');
$this->db->order_by('date_art','desc');
$this->db->limit($limit, $offset);
$query = $this->db->get('gk_blog_posts');
return $query->result();
THe above code is my model file and in the views, I have this:
Code:
<?php foreach($blog_articles as $p): ?>
<div class="articles">
<ul>
<li class="article_date"><?php echo $p->article_date; ?></li>
<li class="article_title author-<?php $p->author_art; ?>"><?php echo anchor('/article/'.$p->id_art.'-'.url_title($p->title_art),$p->title_art); ?></li>
<li class="article_meta"><span class="article_commentsLink"><?php echo anchor('/article/'.$p->id_art.'-'.$p->name_art.'#comments', $p->TotalComments. ' Comments'); ?></span>
</li>
<li><?php echo $p->desc_art; ?></li>
<li> </li>
<li class="article_readmorelink"><?php echo anchor('/article/'.$p->id_art.'-'.url_title($p->title_art),'Continue reading »'); ?></li>
<li>
<span class="article_category">Filed In: <?php echo anchor('/blog-category/'.$p->id_top.'-'.url_title($p->title_top),$p->title_top); ?></span></li>
<li class="article_socialbits"><!-- AddThis Button BEGIN -->
<a href="http://www.addthis.com/bookmark.php"
style="text-decoration:none;"
>id_art . "-" . url_title($p->title_art); ?>', '<?php echo $p->title_art; ?>');"
onmouseout="addthis_close();"
onclick="return addthis_sendto();"><img
src="http://s7.addthis.com/static/btn/sm-plus.gif"
width="16" height="16" border="0" alt="Share" /> Share Bookmark</a>
[removed][removed]
<!-- AddThis Button END -->
</li>
</ul>
</div>
<br />
<br />
<?php endforeach; ?>
Hope it helps...