WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] show last comments from a category post

[Resolved] show last comments from a category post

  • im just turning crazy trying to figure out how (in the main page) i can show the last comments from a post
    i have 3 columns, where i call the last post from a category, so, in each extract, i want to show the last two comments from those post
    any idea?

    im using
    <?php $recent = new WP_Query("cat=6&showposts=1"); while($recent->have_posts()) : $recent->the_post();?><?php endwhile; ?>

    inside there i bring title, featured img, extract and link
    but cant show the last two comments

    thanks a lot

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Michael

    @alchymyth

    Forum Moderator

    im trying with that option
    the problem is, that is showing all comments of the site
    and not of that post

    for example

    i have

    <?php $recent = new WP_Query("cat=5&showposts=1");
    while($recent->have_posts()) : $recent->the_post();?>
    <?php $comments = get_comments(''); foreach($comments as $comment) :
    echo($comment->comment_author .
    ' says: <br />' . $comment->comment_content); endforeach; ?>
    <?php endwhile; ?>

    Moderator Michael

    @alchymyth

    Forum Moderator

    get_comments() has a list of parameter – you might have seen these while reading the link i posted.

    (that is the reason i post links – because they are related to the question and contain information 😉

    yes
    i check that and also apply
    but the problem seems in the quer im making
    coss, instead of get comments from that post, it shows from all the site
    and the get_comments() is inside the query wich search the latest post of a X category

    Moderator Michael

    @alchymyth

    Forum Moderator

    example (using the parameter of get_comments() such as 'post_id' and 'number' to restrict the comments to show only 2 comments of the post):

    <?php $recent = new WP_Query("cat=5&showposts=1");
    while($recent->have_posts()) : $recent->the_post();?>
    <?php $comments = get_comments('post_id=' . $post->ID . '&number=2');
    if($comments) {
    foreach($comments as $comment) :
    echo($comment->comment_author .
    ' says: <br />' . $comment->comment_content); endforeach;
    } ?>
    <?php endwhile; ?>

    you were right
    the problem was not in the query
    was on the parameters of get_comments
    thanks a lot!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] show last comments from a category post’ is closed to new replies.