Forked from banago/old-style-recent-comments.php
Last active
August 29, 2015 14:07
-
-
Save BSG-75/10aba76670693edbe246 to your computer and use it in GitHub Desktop.
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
function bg_recent_comments($no_comments = 10, $comment_len = 35) { | |
global $wpdb; | |
$request = "SELECT * FROM $wpdb->comments"; | |
$request .= " JOIN $wpdb->posts ON ID = comment_post_ID"; | |
$request .= " WHERE comment_approved = '1' AND post_status = 'publish' AND post_password =''"; | |
$request .= " ORDER BY comment_date DESC LIMIT $no_comments"; | |
$comments = $wpdb->get_results($request); | |
if ($comments) { | |
foreach ($comments as $comment) { | |
ob_start(); | |
?> | |
<li> | |
<a href="<?php echo get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; ?>"><?php echo dp_get_author($comment); ?>:</a> | |
<?php echo strip_tags(substr(apply_filters('get_comment_text', $comment->comment_content), 0, $comment_len)); ?> | |
</li> | |
<?php | |
ob_end_flush(); | |
} | |
} else { | |
echo '<li>'.__('No comments', 'banago').'</li>'; | |
} | |
} |
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 get_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
.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; font-family: 'Rokkitt',Arial,sans-serif; 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
/** | |
* 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 get_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 = ''; | |
$comm .= '<ul>'; | |
if ( $comments ) : foreach ( $comments as $comment ) : | |
$comm .= '<li>' . get_avatar( $comment->comment_author_email, $avatar_size ); | |
$comm .= '<a class="author" href="' . get_permalink( $comment->post_ID ) . '#comment-' . $comment->comment_ID . '">'; | |
$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 .= '<li>No comments.</li>'; | |
$comm .= '</ul>'; | |
endif; | |
echo $comm; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This fork makes the following changes: