在WordPress儀表盤的“概況(Right Now)”小工具會顯示文章、分類、評論等數據,今天倡萌就分享下在WordPress儀表盤“概況”小工具顯示自定義文章類型的數據的方法。

將下面的代碼添加到當前主題的 functions.php 文件即可:
//在WordPress儀表盤“概況”顯示自定義文章類型數據(在WP 3.5.2 測試通過)
function wph_right_now_content_table_end() {
$args = array(
'public' => true ,
'_builtin' => false
);
$output = 'object';
$operator = 'and';
$post_types = get_post_types( $args , $output , $operator );
foreach( $post_types as $post_type ) {
$num_posts = wp_count_posts( $post_type->name );
$num = number_format_i18n( $num_posts->publish );
$text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) );
if ( current_user_can( 'edit_posts' ) ) {
$num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
$text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
}
echo '<tr><td class="first num b b-' . $post_type->name . '">' . $num . '</td>';
echo '<td class="text t ' . $post_type->name . '">' . $text . '</td></tr>';
}
$taxonomies = get_taxonomies( $args , $output , $operator );
foreach( $taxonomies as $taxonomy ) {
$num_terms = wp_count_terms( $taxonomy->name );
$num = number_format_i18n( $num_terms );
$text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms ));
if ( current_user_can( 'manage_categories' ) ) {
$num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
$text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
}
echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
}
}
add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );
參考資料:http://wordpress.stackexchange.com/questions/1567/best-collection-of-code-for-your-functions-php-file
聲明:本站所有文章,如無特殊說明或標注,均為本站原創(chuàng)發(fā)布。任何個人或組織,在未征得本站同意時,禁止復制、盜用、采集、發(fā)布本站內容到任何網站、書籍等各類媒體平臺。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。





我想咨詢一下!萌哥!我打算用代碼去除后臺儀表盤里的【活動】小工具!求代碼援助!
校長都是哪里找的 每天都有更新
看文章的參考資料就知道我是在老外的網站找的了,話說我訂閱了好幾十個老外的網站,平時沒事在google搜索WordPress關鍵詞(一般搜英文),你就會發(fā)現很多不錯的博客和文章。每天都更新,是我對自己的要求,必須做到的
基本我每天都會來大學看看 有時有好用的就收藏了 已經收藏不少了