Skip to content

Instantly share code, notes, and snippets.

@jukra
Created September 3, 2014 19:32
Show Gist options
  • Save jukra/fc39d1b17df8a55acf89 to your computer and use it in GitHub Desktop.
Save jukra/fc39d1b17df8a55acf89 to your computer and use it in GitHub Desktop.
Wordpress recent comments
<?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