WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show latest post with number of comments (3 posts)

  1. betadog
    Member
    Posted 5 years ago #

    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.

  2. MichaelH
    Member
    Posted 5 years ago #

    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

  3. betadog
    Member
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic