基于此Answer, 这很容易。
Result:
Code:
检查评论
// ID of the post/page that we want a separate list of comments
$the_id = \'1\';
add_action( \'current_screen\', \'wpse_73581_exclude_lazy_hook\' , 10, 2 );
/**
* Delay hooking our clauses filter to ensure it\'s only applied when needed.
*/
function wpse_73581_exclude_lazy_hook( $screen )
{
if ( $screen->id != \'edit-comments\' )
return;
// Check if our Query Var is defined
if ( isset( $_GET[\'hello_world\'] ) )
add_action( \'pre_get_comments\', \'wpse_73581_list_one_post_comments\', 10, 1 );
add_filter( \'comment_status_links\', \'wpse_73581_link_to_hello_world\' );
}
/**
* Only display comments from specific post
*/
function wpse_73581_list_one_post_comments( $clauses )
{
global $the_id;
$clauses->query_vars[\'post_id\'] = $the_id;
}
/**
* Add link to list of comments from specific post with counter
*/
function wpse_73581_link_to_hello_world( $status_links )
{
global $wpdb, $the_id;
// Get the number of comments from our post
$count = count(
$wpdb->get_results(
$wpdb->prepare(
"SELECT comment_ID FROM $wpdb->comments
WHERE comment_post_ID = $the_id
AND comment_approved != \'trash\'",
ARRAY_A
)
)
);
// Showing our special page
if ( isset( $_GET[\'hello_world\'] ) )
{
// So we can remove the "current" class that is applied to this link
$status_links[\'all\'] =
\'<a href="edit-comments.php?comment_status=all">\'
. __( \'All\' )
. \'</a>\';
// Our link with "current" class and comments count
$status_links[\'hello_world\'] =
\'<a href="edit-comments.php?comment_status=all&hello_world=1" class="current" style="margin-leff:60px">\'
. __( \'Hello World\' )
. \' <span class="count">(\'
. $count
. \')</a></span>\';
}
// Showing other comments pages (All, Pending, Approved, etc)
else
{
$status_links[\'hello_world\'] =
\'<a href="edit-comments.php?comment_status=all&hello_world=1" style="margin-leff:60px">\'
. __( \'Hello World\' )
. \' <span class="count">(\'
. $count
. \')</span></a>\';
}
return $status_links;
}