在主题函数中添加以下代码。php。
// To add extra column in column headers
add_filter(\'manage_posts_columns\', \'bs_event_table_head\');
function bs_event_table_head( $defaults ) {
$defaults[\'pending_comments\'] = \'Pending Comments\';
return $defaults;
}
// To add data in column for each post.
add_action( \'manage_posts_custom_column\', \'bs_event_table_content\', 10, 2 );
function bs_event_table_content( $column_name, $post_id ) {
if ($column_name == \'pending_comments\') {
// getting comments\' counts
$comments_count = wp_count_comments();
$url = admin_url(\'edit-comments.php?comment_status=moderated&p=\');
echo \'<a href="\'.$url.$post_id.\'" title="\'.$comments_count->moderated.\' pending" class="post-com-count"><span class="comment-count">\'.$comments_count->moderated.\'</span></a>\';
}
}
// To make column sortable
add_filter( \'manage_edit-post_sortable_columns\', \'bs_event_table_sorting\' );
function bs_event_table_sorting( $columns ) {
$columns[\'pending_comments\'] = \'pending_comments\';
return $columns;
}