Forums
Home / Fixing WordPress / Recent comments by category
(@linosa)
13 years, 3 months 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?
(@linosa)
13 years, 3 months 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:
I also found this code, but it just gives me 1 comment, and I want the 5 latest:
Any help?