经过一些搜索,我找到了使用manage_edit-${post_type}_columns
过滤器和manage_${post_type}_posts_custom_column
操作的解决方案。
使用过滤器创建列,然后使用操作填充该列。我假设可以使用此链接中的想法轻松添加和填充其他列http://justintadlock.com/archives/2011/06/27/custom-columns-for-custom-post-types
add_filter('manage_edit-article_columns', 'my_columns');
function my_columns($columns) {
$columns['article_category'] = 'Category';
return $columns;
}
add_action( 'manage_article_posts_custom_column', 'my_manage_article_columns', 10, 2 );
function my_manage_article_columns( $column, $post_id ) {
global $post;
switch( $column ) {
/* If displaying the 'article_category' column. */
case 'article_category' :
/* Get the genres for the post. */
$terms = get_the_terms( $post_id, 'article_category' );
/* If terms were found. */
if ( !empty( $terms ) ) {
$out = array();
/* Loop through each term, linking to the 'edit posts' page for the specific term. */
foreach ( $terms as $term ) {
$out[] = sprintf( '<a href="%s">%s</a>',
esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'article_category' => $term->slug ), 'edit.php' ) ),
esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'article_category', 'display' ) )
);
}
/* Join the terms, separating them with a comma. */
echo join( ', ', $out );
}
/* If no terms were found, output a default message. */
else {
_e( 'No Articles' );
}
break;
/* Just break out of the switch statement for everything else. */
default :
break;
}
}