Support » Themes and Templates » Using get_comments on category pages


    I’d like to get the most recent comments within each category and display it in my category archives. Admittedly I have no idea how to approach this situation and I’ve just been trying to mix bits and pieces of code I’ve found on the internet without really understanding what’s going on.

    `<section class=”recentComments”>
    <h1>Recent Comments</h1>
    $show_comments = 10;
    $i = 0;
    $comments = get_comments(“number=50&status=approve”);
    foreach ($comments as $comment)
    $comm_post_id = $comment->comment_post_ID;
    $comm_category = get_the_category($comm_post_id);
    if (!in_category(“$comm_category”)){

    // Output the comment, author and whatever you need
    // I’ll just output the comment excerpt to keep my code simple
    ?><li><?php comment_content(); ?></li><?php

    if ($i >= $real_comments) break;
    echo(“NO POSTS MATCHED”);


    I was using this tutorial: // for reference. No comments are coming up, but I’m also not seeing “No POSTS MATCHED”.

    I would be very much appreciative if someone could explain what’s happening in this code. And how to go about doing things the right way. Thanks!

  • The topic ‘Using get_comments on category pages’ is closed to new replies.