-
-
Save banago/c1a04efce6ebb79a6474 to your computer and use it in GitHub Desktop.
WordPress - Recent Comments without a Plugin or Widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="widget recent-comments"> | |
<h3>Recent Comments</h3> | |
<?php bg_recent_comments(); ?> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if it can ajax load more comments, it will more great!