Answer the question
In order to leave comments, you need to log in
List of recent comments from a specific category?
There is a code for displaying the latest comments. Please tell me how to set the output of the last comments only from a specific category in this code. And how to display the total number of comments in the post near the title of the post?
$comment_len = 140;
$comments = get_comments('status=approve&number=15');
if ($comments) {
foreach ($comments as $comment) {
?>
<li>
<?php echo get_avatar($comment,$size='50' ); ?>
<?php echo $comment->comment_author; ?>
<?php
$d = "j F Y в H:i";
$comment_ID = $comment->comment_ID;
$comment_date = get_comment_date( $d, $comment_ID );
echo $comment_date;
?>
<a href="<?php echo get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; ?>"><?php echo mb_substr( strip_tags( $comment->comment_content ), 0, 75 ); ?>...</a>
<a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo get_the_title($comment->comment_post_ID); ?></a>
</li>
<?php
}
} else {
echo "<li>Комментарии отсутствуют</li>";
}
Answer the question
In order to leave comments, you need to log in
Perhaps not the most juicy solution, but you do not have enough selection of posts of the necessary headings.
Add something like:
<?php
$needed_ids = array();
$posts = get_posts( array('category' => /* id или slug-и нужных рубрик*/) );
foreach( $posts as $post ){ array_push($needed_ids, $post->ID); }
?>
'post__in' => $needed_ids
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question