这类似于向常规帖子添加列,只是过滤器和操作略有不同:manage_edit-{$post_type}_columns
和manage_{$post_type}_posts_custom_column
function wpse27787_add_video_column( $columns ){
// add a new column to array of columns
// can also unset columns here to remove them
$columns[\'length\'] = __(\'Length\');
return $columns;
}
function wpse27787_manage_video_columns( $column_name, $id ){
// if this is our custom column, fetch whatever data we want to output
if( $column_name == \'length\' ):
// get your video length here using this post\'s $id and
echo $this_length;
endif;
}
function wpse27787_init() {
// add our filter and action on admin_init
add_filter( \'manage_edit-video_columns\', \'wpse27787_add_video_column\' );
add_action( \'manage_video_posts_custom_column\', \'wpse27787_manage_video_columns\', 10, 2 );
}
add_action( \'admin_init\' , \'wpse27787_init\' );
EDIT -
如果要对列重新排序,请使用原始列的值创建一个新数组,将列添加到所需位置:
function wpse27787_add_video_column( $columns ){
foreach( $columns as $key => $val):
$reordered_columns[$key] = $val;
if( $key == \'title\' ):
// add our custom column after title
$reordered_columns[\'length\'] = __(\'Length\');
endif;
endforeach;
return $reordered_columns;
}