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

  • Resolved betadog

    (@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)
  • MichaelH

    (@michaelh)

    Try:

    <?php
    $args=array(
      'showposts'=>1,
      'caller_get_posts'=>1
       );
    $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>
    
    <?php
    echo 'comment count is: ' . $post->comment_count;
    endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Review:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

    betadog

    (@betadog)

    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.