Y
Y
Ysery2021-07-02 23:43:50
WordPress
Ysery, 2021-07-02 23:43:50

List of recent comments with the exclusion of those from articles of a certain category and vice versa in WordPress, how?

Good day.

There is such a code.

$comment_len = 140;
    $comments = get_comments('status=approve&number=5');
    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>";
    }


How to do:
  • so that all the latest comments (5 comments) are displayed, but those from the articles that are in a certain category are excluded
  • and how to display all the latest comments (5 comments) that were posted in articles that belong only to a certain category


In other words, I want to make a separate category on the site (it is on a different topic). And so that if the user reads an article from this very separate heading, then he will be shown the latest comments that relate to articles in this separate heading. And if he reads any other article on the site (not included in a separate heading), then he was shown the latest comments from articles posted in all other headings.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question