B2主題使用了很多自定義文章類型,比如圈子、商城、文檔、公告、快訊、網(wǎng)址等等,我們可以在儀表盤“概覽”小工具添加這些文章類型的數(shù)據(jù),方便我們了解相關(guān)信息,效果如下圖:

按照自己的需要修改下面代碼的第8行,然后將代碼添加到子主題的 functions.php 中即可:
/**
* 儀表盤“概覽”小工具添加其他文章類型數(shù)據(jù)
* http://www.ydqwiac.cn/docs/b2/b2-dev/dashboard-overview
*/
function b2child_add_custom_post_counts() {
// 根據(jù)你的需要修改下面array()里面的文章類型別名即可
$post_types = array( 'shop', 'announcement', 'newsflashes', 'circle', 'links' );
foreach ( $post_types as $cpt ) {
$cpt_info = get_post_type_object( $cpt );
$num_posts = wp_count_posts( $cpt );
$num = number_format_i18n( $num_posts->publish );
$text = _n( $cpt_info->labels->singular_name, $cpt_info->labels->singular_name, intval( $num_posts->publish ) );
echo '<li class="page-count '. esc_attr( $cpt_info->name ) . '-count"><a href="edit.php?post_type=' . esc_attr( $cpt ) . '">' . $num . ' ' . $text . '</a></li>';
}
}
add_action( 'dashboard_glance_items', 'b2child_add_custom_post_counts' );
如果你要查看文章類型的值,可以在后臺(tái)點(diǎn)擊對應(yīng)文章類型導(dǎo)航菜單下的第一個(gè)子菜單,比如頁面-全部頁面,就可以在網(wǎng)址中看到?/wp-admin/edit.php?post_type=page,其中?post_type=?后面的值,就是文章類型的值了,比如頁面就是?page。




感謝大佬分享教程,請問如何顯示用戶數(shù)量呢。再加上用戶數(shù)量就可以相對完整的看到一個(gè)網(wǎng)站的數(shù)據(jù)了?