Standing on the Shoulder of Linus

Home / 2010 / 10月 / 16 / Number of Custom Post Type on your Dashboard

Number of Custom Post Type on your Dashboard

You can use Custom Post Type in WordPress 3.0. By default, Number of Custom Post Type is now shown in “Right Now” on your Dashboard. You can see how many Custom Post Type you posted, by adding the following code on your functions.php.

Please fill in the label of the custom post type. For example, you are using an “event” post type, $custom_post_type = 'event';.

function custom_post_dashboard() {
    $custom_post_type = 'event'; // Fill in the label of CPT
    global $wp_post_types;
    $num_post_type = wp_count_posts( $custom_post_type );
    $num = number_format_i18n($num_post_type->publish);
    $text = _n( $wp_post_types[$custom_post_type]->labels->singular_name, $wp_post_types[$custom_post_type]->labels->name, $num_post_type->publish );
    $capability = $wp_post_types[$custom_post_type]->cap->edit_posts;

    if (current_user_can($capability)) {
        $num = "<a href='edit.php?post_type=" . $custom_post_type . "'>$num</a>";
        $text = "<a href='edit.php?post_type=" . $custom_post_type . "'>$text</a>";
    }

    echo '<tr>';
    echo '<td class="first b b_' . $custom_post_type . '">' . $num . '</td>';
    echo '<td class="t ' . $custom_post_type . '">' . $text . '</td>';
    echo '</tr>';
}
add_action('right_now_content_table_end', 'custom_post_dashboard');

Here, right_now_content_table_end is a name of action hook.

The picture is a dashboard with an additional row “イベント” (Japanese word for “event”). If users are allowed to edit the posts of this custom post type, they can click the link and go to edit.php.

関連

← カスタム投稿タイプの投稿数をダッシュボードに表示する WordCamp 名古屋 2010 →

アーカイブ

人気の投稿とページ

  • キンドル本を印刷する(PDFに変換する)方法
  • 名古屋駅から国際センターまでの道のり(徒歩)
  • AGPL ライセンス(GPLとは似ているが違いもある)
  • 6年使ったイーモバイル(Y!mobile)を解約手続。店頭でSIM返却
  • JP-Secure SiteGuard WP Pluginは不正ログイン防止に役立つか

プロフィール

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

Copyright © 2015 Standing on the Shoulder of Linus.