注意-
它使用存储在全局变量-
wp_query
. 通常是
wp_query
变量包含浏览时当前帖子的注释。
Usage -
$comments = wpse61072_hide_admin_comment(5); // 5=max comments
foreach ( $comments as $comment ) {
echo \'<li>\'.$comment->comment_author.\' - said : \'.$comment->comment_content.\'</li>\';
}
Functions.php -
/*
* Usage : $comments = wpse61072_hide_admin_comment($post->ID, 5);
* Show Count : echo count(wpse61072_hide_admin_comment($post->ID, 5));
* This goes into functions.php
*/
function wpse61072_hide_admin_comment ( $post_id, $no ) {
global $wp_query; // uses global variable
$woa_comments = $wp_query->comments;
//thanks @kaiser for loop
foreach ( $woa_comments as $woa_comment => $woac ) {
$author = get_userdata( $woac->user_id );
if (user_can( $author, \'manage_options\' )) {
unset( $woa_comments[ $woa_comment ] );
}
}
//make sure we\'re returing only specified elements
return (array_slice($woa_comments,0,$no));
}
测试日期
wordpress 3.4.1 具有
TwentyTen 主题