Welcome Guest, Not a member yet? Register   Sign In
Showing number of comments in blog (while listing all posts)
#3

[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">&lt;?php echo $p->article_date; ?&gt;</li>
            <li class="article_title author-&lt;?php $p->author_art; ?&gt;">&lt;?php echo anchor('/article/'.$p->id_art.'-'.url_title($p->title_art),$p->title_art); ?&gt;</li>
            <li class="article_meta"><span class="article_commentsLink">&lt;?php echo anchor('/article/'.$p->id_art.'-'.$p->name_art.'#comments', $p->TotalComments. ' Comments'); ?&gt;</span>
            </li>
              <li>&lt;?php echo $p->desc_art; ?&gt;</li>
            <li>&nbsp;</li>
              <li class="article_readmorelink">&lt;?php echo anchor('/article/'.$p->id_art.'-'.url_title($p->title_art),'Continue reading &raquo;'); ?&gt;</li>
              <li>
                <span class="article_category">Filed In: &lt;?php echo anchor('/blog-category/'.$p->id_top.'-'.url_title($p->title_top),$p->title_top); ?&gt;</span></li>
            <li class="article_socialbits">&lt;!-- AddThis Button BEGIN --&gt;
                    <a href="http://www.addthis.com/bookmark.php"
                        style="text-decoration:none;"
                       >id_art . "-" . url_title($p->title_art); ?&gt;', '&lt;?php echo $p->title_art; ?&gt;');"
                        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]
&lt;!-- AddThis Button END --&gt;
            </li>
        </ul>
    </div>
    <br />
    <br />
&lt;?php endforeach; ?&gt;

Hope it helps...


Messages In This Thread
Showing number of comments in blog (while listing all posts) - by El Forum - 09-07-2009, 08:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB