“概览”小工具添加其他文章类型数据

2024-02-01 14:01 小编

B2主题使用了很多自定义文章类型,比如圈子、商城、文档、公告、快讯、网址等等,我们可以在仪表盘“概览”小工具添加这些文章类型的数据,方便我们了解相关信息,效果如下图:

“概览”小工具添加其他文章类型数据 - Dashboard Right Now

按照自己的需要修改下面代码的第8行,然后将代码添加到子主题的 functions.php 中即可:

/** * 仪表盘“概览”小工具添加其他文章类型数据 * https://www.wpdaxue.com/docs/b2/b2-dev/dashboard-overview */function b2child_add_custom_post_counts() {    // 根据你的需要修改下面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' );

如果你要查看文章类型的值,可以在后台点击对应文章类型导航菜单下的第一个子菜单,比如页面-全部页面,就可以在网址中看到 /wp-admin/edit.php?post_type=page,其中 post_type= 后面的值,就是文章类型的值了,比如页面就是 page


在线咨询 拨打电话

电话

13363039260

微信二维码

微信二维码