Standing on the Shoulder of Linus

Home / 2011 / 4月 / 04 / カスタム分類のターム数をダッシュボードに表示する

カスタム分類のターム数をダッシュボードに表示する

カスタム投稿タイプの投稿数をダッシュボードに表示するの姉妹編です。カスタム分類のターム数をダッシュボードに表示する管理画面カスタマイズです。

利用しているテーマの 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を調べたら、カテゴリーとタグの場合もこの関数で要素数を取得していました。

関連

Posted in myplugin | Tagged WordPress, カスタム分類, 管理画面カスタマイズ
← web2pyでのテスト Hybridテーマの日本語化ファイル →

アーカイブ

人気の投稿とページ

  • キンドル本を印刷する(PDFに変換する)方法
  • 名古屋駅から国際センターまでの道のり(徒歩)
  • AGPL ライセンス(GPLとは似ているが違いもある)
  • 問い合わせフォーム改善: 選択肢により条件分岐し、項目の表示非表示を変更する
  • JP-Secure SiteGuard WP Pluginは不正ログイン防止に役立つか

プロフィール

水野史土:月70万PVホームページ制作会社のレスキューワーク株式会社で、PHPソフトウェアのサポートを行っている。concrete5コミュニティリーダー、Novius OSコアコード貢献者でもある。 詳しくは管理者詳細参照。
大好評WordPress書籍「WordPressユーザーのためのPHP入門 はじめから、ていねいに。」サポートページ

Copyright © 2015 Standing on the Shoulder of Linus.