Created
September 3, 2014 19:32
-
-
Save jukra/fc39d1b17df8a55acf89 to your computer and use it in GitHub Desktop.
Wordpress recent comments
This file contains hidden or 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 | |
function my_recent_comments() { | |
$d = "j.n.Y H:i"; //Date format, set your own | |
$comments_query = new WP_Comment_Query();` | |
$comments = $comments_query->query( array( 'number' => '6', 'post_id' => '65', ) ); //How many comments and in which post | |
$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_comment_author( $comment->comment_ID ) . '</a> '; | |
$comm .= get_comment_date( $d, $comment->comment_ID ) .'</li>'; | |
endforeach; else : | |
$comm .= 'No comments.'; //If no comments are found | |
endif; | |
return $comm; | |
} | |
add_shortcode('recent-comments', 'my_recent_comments'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment