投稿一覧に「サムネイル」「ID」「スラッグ」「文字数」の4項目を追加
function add_posts_columns($columns) {
$columns['thumbnail'] = 'サムネイル';
$columns['postid'] = 'ID';
$columns['slug'] = 'スラッグ';
$columns['count'] = '文字数';
echo '<style type="text/css">
.fixed .column-thumbnail {width: 80px;}
.fixed .column-postid {width: 4%;}
.fixed .column-slug, .fixed .column-count {width: 9%;}
</style>';
return $columns;
}
function add_posts_columns_row($column_name, $post_id) {
if ( 'thumbnail' == $column_name ) {
$thumb = get_the_post_thumbnail($post_id, array(60,60), 'thumbnail');
echo ( $thumb ) ? $thumb : '-';
} elseif ( 'postid' == $column_name ) {
echo $post_id;
} elseif ( 'slug' == $column_name ) {
$slug = get_post($post_id) -> post_name;
echo $slug;
} elseif ( 'count' == $column_name ) {
$count = mb_strlen(strip_tags(get_post_field('post_content', $post_id)));
echo $count;
}
}
add_filter( 'manage_posts_columns', 'add_posts_columns' );
add_action( 'manage_posts_custom_column', 'add_posts_columns_row', 10, 2 );