Support » Plugins and Hacks » Hacks » Showing only the last 3 comments for a post / page

  • Jon

    (@jonpaulwade)


    For my mobile theme I wish to show only the last 3 comments for that post (or page) and the new comment form.

    I added this code to the comments.php

    <?php $args = array(
        'number' => 3,
        'post_id' => $post->ID,
        'status' => 'approve'
    );
    $latest_comment = get_comments( $args );
    if( $latest_comment ) foreach( $latest_comment as $comment ) { ?>
    <?php echo $comment->comment_author; ?>: <?php echo wp_html_excerpt( $comment->comment_content, 500 ); ?>..."<br /><br />
    <?php } ?>
    </p>
    <p>
    To read all questions and answers view the website on a desktop or tablet.
    </p>
    <p>
    <b>Ask a Question / Leave a Comment:</b>
    </p>
    <?php comment_form(array('comment_notes_after' => '')); ?>

    However, this shows the last 3 comments for the whole site, not for that page. Better than showing all comments (some pages have hundreds) but not what I wanted to do.

    Does anybody know how to get the current page comments to show?

    Many thanks

    Jon.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Showing only the last 3 comments for a post / page’ is closed to new replies.