【WP管理画面カスタム】投稿一覧の表示項目を増やす

2018/11/12

ヒストリーとメモ。

はてはて。
なぜか管理画面のカスタマイズが好き♡

 

// 管理画面の投稿ページの表示項目を増やす

function add_posts_columns($columns) {
$columns['thumbnail'] = 'アイキャッチ';
$columns['postid'] = 'ID';
$columns['slug'] = 'スラッグ';
$columns['count'] = '字数';
$columns['robots'] = 'index';

echo '<style type="text/css">
    .fixed .column-thumbnail {width: 120px;}
        .fixed .column-postid {width: 60px;}
        .fixed .column-slug, .fixed .column-count {width: 5%;}
        .fixed .column-robots {width: 60px;}
    </style>';

return $columns;
}
function add_posts_columns_row($column_name, $post_id) {
if ( 'thumbnail' == $column_name ) {
$thumb = get_the_post_thumbnail($post_id, array(100,100), 'thumbnail');
echo ( $thumb ) ? $thumb : '-';
} elseif ( 'postid' == $column_name ) {
echo $post_id;
} elseif ( 'slug' == $column_name ) {
$slug = get_post($post_id) -&gt; post_name;
echo $slug;
} elseif ( 'count' == $column_name ) {
$count = mb_strlen(strip_tags(get_post_field('post_content', $post_id)));
echo $count;
} elseif ( 'robots' == $column_name ) {
$robots = get_post_meta($post_id, 'stmeta_robots', true);
echo $robots;
}
}
add_filter( 'manage_posts_columns', 'add_posts_columns' );
add_action( 'manage_posts_custom_column', 'add_posts_columns_row', 10, 2 );

// ここまで管理画面の投稿ページの表示項目を増やす

// 管理画面の固定ページの表示項目を増やす

function add_page_columns($columns) {
$columns['thumbnail'] = 'アイキャッチ';
$columns['slug'] = 'スラッグ';
$columns['robots'] = 'index';
return $columns;
}
function add_page_column_row($column_name, $post_id) {
if ( 'thumbnail' == $column_name ) {
$thumb = get_the_post_thumbnail($post_id, array(100,100), 'thumbnail');
echo ( $thumb ) ? $thumb : '-';
} elseif ( 'slug' == $column_name ) {
$slug = get_post($post_id) -&gt; post_name;
echo $slug;
} elseif ( 'robots' == $column_name ) {
$robots = get_post_meta($post_id, 'stmeta_robots', true);
echo $robots;
}
}
add_filter( 'manage_pages_columns', 'add_page_columns');
add_action( 'manage_pages_custom_column', 'add_page_column_row', 10, 2);

// ここまで 管理画面の固定ページの表示項目を増やす