Support » Fixing WordPress » how to add comment counts in mini loop on static pages

  • I’m pretty new to WordPress, so this may be a very simple question…I hope it is.

    I’m in the process of creating a new web site that’s centered around a WordPress blog. Aside from the blog, I have about 23 static, non WordPress pages. Every page needs to have in its sidebar a list of the five most recent posts. This I’ve done by changing my HTML pages to PHP, and adding the following code, lifted from a codex page:

    <?
    $news=$wpdb->get_results("SELECT
    ID,post_title FROM $wpdb->posts
    WHERE post_status= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
    foreach($news as $np){
    printf ("<a href=\"..wordpressindex.php?p=%s\">%s</a><BR>", $np->ID,$np->post_title);
    }?>

    It works great, but I can’t figure out how to add the comment counts to the end of each post title. I’ve done it on the wordpress pages with this

    <?php comments_popup_link('[0]', '[1]', '[%]'); ?>

    inside the

    <?php while (have_posts()) : the_post(); ?>

    tags. Any help will be greatly appreciated…go WordPress!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Dan, I came across your post while looking for the same information. I finally got it! This is the tage you need

    <?php comments_template(); ?>

    If you want to see the discussion around it see here.

    http://wordpress.org/support/topic/68104?replies=8

    I hope that does it because I am obviously a newbie as well so I probably can’t help if this isn’t the answer you are looking for.

    Hmm, unfortunately that’s not really what I’m trying to do. I’m not looking to add comment functionality to these pages, just to have a count of the comments appear next to the links I’ve incoluded to the five most recent posts.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to add comment counts in mini loop on static pages’ is closed to new replies.