カスタム投稿タイプの投稿数をダッシュボードに表示するの姉妹編です。カスタム分類のターム数をダッシュボードに表示する管理画面カスタマイズです。
利用しているテーマの functions.php に下記コードを書けばOKです。「現在の状況」に追加して表示します。$my_custom_tax = 'areas'の部分は、register_taxonomyで定義したラベル名を書いてください。
function custom_tax_dashboard() {
$my_custom_tax = 'areas'; // カスタム分類のラベル
$tax_info = get_taxonomy($my_custom_tax);
$num_tax = wp_count_terms($my_custom_tax);
$num = number_format_i18n($num_tax);
$text = _n( $tax_info->labels->singular_name, $tax_info->labels->name, $num_tax );
$capability = $tax_info->cap->manage_terms;
if (current_user_can($capability)) {
$num = "<a href='edit-tags.php?taxonomy=" . $my_custom_tax . "'>$num</a>";
$text = "<a href='edit-tags.php?taxonomy=" . $my_custom_tax . "'>$text</a>";
}
echo '<tr>';
echo '<td class="first b b_' . $my_custom_tax . '">' . $num . '</td>';
echo '<td class="t ' . $my_custom_tax . '">' . $text . '</td>';
echo '</tr>';
}
add_action('right_now_content_table_end', 'custom_tax_dashboard');
カスタム分類の場合は、wp_count_termsで取得できます。dashboard.phpを調べたら、カテゴリーとタグの場合もこの関数で要素数を取得していました。
