发新话题
打印

[问题求助] 求分类的文章统计函数(php),自己修改代码

求分类的文章统计函数(php),自己修改代码

有些分类统计的插件和函数只能统计所有的文章,即总数,我求一个分类统计的插件或函数(如果wordpress已经有这个函数的话),我的博客(http://myet.info)现在只有总数统计,用的是wordpress自带的统计函数,我看到很多博客都有分类文章的统计,请高手指点一下,谢谢了。

TOP

http://www.gengbing.com/aboutme/
我的右侧栏的是我自己修改的
根据后台首页的代码来的
是不是要这样的?如果是的话我加上代码
这是个链接=>逍遥老鬼继续扯淡

TOP

复制内容到剪贴板
代码:
统计


<?php
$num_posts = wp_count_posts( 'post' );
$num_pages = wp_count_posts( 'page' );
$num_cats = wp_count_terms('category');
$num_tags = wp_count_terms('post_tag');
$num_comm = get_comment_count( );

$post_type_texts = array();

if ( !empty($num_posts->publish) ) { // with feeds, anyone can tell how many posts there are. Just unlink if !current_user_can
$post_text = sprintf( __ngettext( '%s post', '%s posts', $num_posts->publish ), number_format_i18n( $num_posts->publish ) );
$post_type_texts[] = $can_edit_posts ? "$post_text" : $post_text;
}
if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds. Don't show if !current_user_can
$post_type_texts[] = ''.sprintf( __ngettext( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'';
}
if ( $can_edit_posts && !empty($num_posts->draft) ) {
$post_type_texts[] = ''.sprintf( __ngettext( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'';
}
if ( $can_edit_posts && !empty($num_posts->future) ) {
$post_type_texts[] = ''.sprintf( __ngettext( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'';
}

if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
$pending_text = sprintf( __ngettext( 'There is %2$s post pending your review.', 'There are %2$s posts pending your review.', $num_posts->pending ), 'edit.php?post_status=pending', number_format_i18n( $num_posts->pending ) );
} else {
$pending_text = '';
}

$cats_text = sprintf( __ngettext( '%s category', '%s categories', $num_cats ), number_format_i18n( $num_cats ) );
$tags_text = sprintf( __ngettext( '%s tag', '%s tags', $num_tags ), number_format_i18n( $num_tags ) );
if ( current_user_can( 'manage_categories' ) ) {
$cats_text = "$cats_text";
$tags_text = "$tags_text";
}

$total_comments = sprintf( __ngettext( '%1$s total', '%1$s total', $num_comm['total_comments'] ), number_format_i18n($num_comm['total_comments']) );
$approved_comments = sprintf( __ngettext( '%1$s approved', '%1$s approved', $num_comm['approved'] ), number_format_i18n($num_comm['approved']) );
$spam_comments = sprintf( __ngettext( '%1$s spam', '%1$s spam', $num_comm['spam'] ), number_format_i18n($num_comm['spam']) );
$moderated_comments = sprintf( __ngettext( '%1$s awaiting moderation', '%1$s awaiting moderation', $num_comm['awaiting_moderation'] ), number_format_i18n($num_comm['awaiting_moderation']) );

if( current_user_can( 'moderate_comments' ) ) {
$total_comments = "{$total_comments}";
$approved_comments = "{$approved_comments}";
$moderated_comments = "{$moderated_comments}";
}

$comm_text = sprintf( __ngettext( '
%1$s
%2$s
%4$s', '
%1$s
%2$s
%4$s', $num_comm['total_comments'] ), $total_comments, $approved_comments, $spam_comments, $moderated_comments );

$post_type_text = implode(', ', $post_type_texts);

// There is always a category
$sentence = sprintf( __( '
%1$s
%2$s
%3$s%5$s' ), $post_type_text, $cats_text, $tags_text, $pending_text, $comm_text );
$sentence = apply_filters( 'dashboard_count_sentence', $sentence, $post_type_text, $cats_text, $tags_text, $pending_text);

?>
这是个链接=>逍遥老鬼继续扯淡

TOP

谢谢逍遥老鬼

我昨天又用Widgets 代替了自己修改代码了,而且我把Widgets页修改的和之前的一样了。谢谢你了,呵呵
我打开你博客的时候,右边栏跑到下边去了,是不是不支持1024*768啊。
我的博客:http://myet.info

TOP

发新话题