Skip to content

Instantly share code, notes, and snippets.

@banago

banago/recent-comments.css Secret

Last active Dec 6, 2017
Embed
What would you like to do?
WordPress - Recent Comments without a Plugin or Widget
.recent-comments { list-style: none; font-size: 12px; color: #485358; }
.recent-comments li { overflow: hidden; padding: 20px 0; border-top: 1px dotted #DADEE1; }
.recent-comments li:first-child { border: 0 none; }
.recent-comments img { float: left; margin-right: 8px; }
.recent-comments a { display: block; margin-top: 10px; padding-top: 10px; text-transform: uppercase; }
<div class="widget recent-comments">
<h3>Recent Comments</h3>
<?php bg_recent_comments(); ?>
</div>
<?php
/**
* Show Recent Comments
*
* @author Baki Goxhaj
* @link http://wplancer.com/how-to-display-recent-comments-without-using-a-plugin-or-widget/
*
* @param string/integer $no_comments
* @param string/integer $comment_len
* @param string/integer $avatar_size
*
* @echo string $comm
*/
function bg_recent_comments($no_comments = 5, $comment_len = 80, $avatar_size = 48) {
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query( array( 'number' => $no_comments ) );
$comm = '';
if ( $comments ) : foreach ( $comments as $comment ) :
$comm .= '<li><a class="author" href="' . get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID . '">';
$comm .= get_avatar( $comment->comment_author_email, $avatar_size );
$comm .= get_comment_author( $comment->comment_ID ) . ':</a> ';
$comm .= '<p>' . strip_tags( substr( apply_filters( 'get_comment_text', $comment->comment_content ), 0, $comment_len ) ) . '...</p></li>';
endforeach; else :
$comm .= 'No comments.';
endif;
echo $comm;
}
@llity

This comment has been minimized.

Copy link

@llity llity commented Jan 7, 2016

if it can ajax load more comments, it will more great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.