Support » Themes and Templates » Show latest post with number of comments

  • Resolved betadog


    I would like to display

    – the most recent post
    – AND the number of comments for that particular post
    – on my main page.

    That’s all.

    I am having a hard time finding the right code in the Codex, any help is appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try:

    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    echo 'comment count is: ' . $post->comment_count;
    wp_reset_query();  // Restore global post data stomped by the_post().

    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

    MichaelH, I stand in awe of your mad PHP-Skills. I can’t thank you enough, it works like a charm.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show latest post with number of comments’ is closed to new replies.