WordPress.org

Ready to get started?Download WordPress

Forums

Recent comments by category (1 post)

  1. Linosa
    Member
    Posted 3 years ago #

    I'm trying to get a list of recent comments (the latest) from a specific category, but I don't get it to work.

    When I use the "normal" code it gives me comments from all categories:

    <?php
    $args = array(
    	'status' => 'approve',
    	'number' => '5',
    );
    $comments = get_comments($args);
    foreach($comments as $comment) :
    	echo($comment->comment_author . '<br />' . $comment->comment_content);
    endforeach;
    ?>

    I also found this code, but it just gives me 1 comment, and I want the 5 latest:

    <?php
    $show_comments = 20;
    $i = 0;
    $comments = get_comments("status=approve");
    foreach ($comments as $comment)
    {
    	$comm_post_id = $comment->comment_post_ID;
    	if (!in_category("nyheter", $comm_post_id))
    		continue;
    	$i++;
    	?><li><?php comment_excerpt(); ?></li><?php
    
    	if ($i >= $real_comments) break;
    }
    ?>

    Any help?

Topic Closed

This topic has been closed to new replies.

About this Topic