Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Last active December 10, 2015 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save thefuxia/4503390 to your computer and use it in GitHub Desktop.
Save thefuxia/4503390 to your computer and use it in GitHub Desktop.
T5 Comment List Shortcode
<?php
/**
* Plugin Name: T5 Comment List Shortcode
* Description: Use [listcomments post_id="NUMBER"] to list comments from another post.
* Plugin URI:
* Version: 2013.01.10
* Author: Thomas Scholz
* Author URI: http://toscho.de
* Licence: MIT
* License URI: http://opensource.org/licenses/MIT
*/
add_shortcode( 'listcomments', 't5_list_comments' );
function t5_list_comments( $atts, $content = '' )
{
'' !== $content && $content = wpautop( do_shortcode( $content ) );
if ( ! isset ( $atts['post_id'] ) )
return 'Please pass an argument for "post_id"';
if ( ! $comments = get_comments( $atts ) )
return 'No comments found for post ID '. esc_html( $atts['post_id'] );
$out = $content . '<ul class="t5-comment-list">';
foreach ( $comments as $comment )
{
$out .= sprintf(
'<li>%1$s%2$s</li>',
get_comment_author_link( $comment->comment_ID ),
wpautop( $comment->comment_content )
);
}
return $out . '</ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment