WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] show last comments from a category post (8 posts)

  1. canutedechou
    Member
    Posted 3 years ago #

    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

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

  3. canutedechou
    Member
    Posted 3 years ago #

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

  4. canutedechou
    Member
    Posted 3 years ago #

    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; ?>
  5. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    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 ;-)

  6. canutedechou
    Member
    Posted 3 years ago #

    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

  7. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    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; ?>
  8. canutedechou
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.