Last active
December 10, 2015 22:38
-
-
Save thefuxia/4503390 to your computer and use it in GitHub Desktop.
T5 Comment List Shortcode
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 | |
/** | |
* 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