A
A
Andrey2018-05-16 22:48:59
WordPress
Andrey, 2018-05-16 22:48:59

Modifying wordpress last comments code?

There is a simple code for displaying the latest comments. Please tell me how to do the following here:
1. Display a relative date like 10 minutes ago, 5 days ago.
2. Display a link to the profile of the author of the comment, if he is registered on the site. If the user is not registered on the site, then the link is not displayed, only the name.

function site_recent_comments() {
    $comment_len = 80;
    $comments = get_comments('number=5');
    if ($comments) {
        foreach ($comments as $comment) {
            ?>
            <li>
                <?php echo get_avatar($comment,$size='40' ); ?>
                <?php echo $comment->comment_author; ?>
            <?php
                  $d = "d M Y, H:i";
                  $comment_ID = $comment->comment_ID;
                  $comment_date = get_comment_date( $d, $comment_ID );
                  echo $comment_date;
                  ?>
        
                   <?php echo mb_substr( strip_tags( $comment->comment_content ), 0, 50 ); ?>...
      <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </li>
            <?php
        }
    } else {
        echo "<li>Комментарии отсутствуют</li>";
    }
}

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