wordpress右边栏文章统计代码

这个代码属于复杂型,是从后台那边提取的,简单的方法我还一直在找,没找到,比较伤!不过找到我会放出来的!

<li><h2>统计</h2>
 <ul class=’blogroll’>
< ?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’, ‘文章数%s’, $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 <a href=”%1$s”>%2$s post</a> pending your review.’, ‘There are <a href=”%1$s”>%2$s posts</a> 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’, ‘分类数:%s’, $num_cats ), number_format_i18n( $num_cats ) );
$tags_text = sprintf( __ngettext( ‘标签数:%s’, ‘标签数:%s’, $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’, ‘总评论:%1$s’, $num_comm['total_comments'] ), number_format_i18n($num_comm['total_comments']) );
$approved_comments = sprintf( __ngettext( ‘已审核:%1$s’, ‘已审核:%1$s’, $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’, ‘未审核:%1$s’, $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}”;
}

$comm_text = sprintf( __ngettext( ‘<li>%1$s</li><li>%2$s</li><li>%4$s</li>’, ‘<li>%1$s</li><li>%2$s</li><li>%4$s</li>’, $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( __( ‘<li>%1$s</li><li>%2$s</li><li>%3$s</li>%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);

?>< ?php echo $sentence; ?>
 </ul>
</li>

标签: