推荐:WordPress博客站点统计代码

在自己的博客上显示博客的一些相关信息,包括:文章数量,评论数量,博客至今运行多少天等等,只需要把以下代码粘贴到适当的位置即可,之后可以根据自己的需要再做调整。

统计代码如下:

<h3>站点统计</h3>
文章数量:<?php $count_posts = wp_count_posts();
 echo $published_posts = $count_posts->publish; ?>
评论数量:<?php $total_comments = get_comment_count();
echo $total_comments['approved'];?>
分类数量:<?php echo $count_categories = wp_count_terms('category'); ?>
页面数量:<?php $count_pages = wp_count_posts('page');
echo $page_posts = $count_pages->publish; ?>
链接数量:<?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links
WHERE link_visible = 'Y'"); echo $link; ?>
标签数量:<?php echo $count_tags = wp_count_terms('post_tag'); ?>
站点成立:某年某月某日(自己填写)
迄今运行:<?php echo floor((time()-strtotime("20xx-x-xx"))/86400); ?>天
最后更新:<?php $last = $wpdb->get_results("SELECT MAX(post_modified)
AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type
= 'page') AND (post_status = 'publish' OR post_status = 'private')");
$last = date('Y年n月j日', strtotime($last[0]->MAX_m));echo $last; ?>

:在“迄今运行”代码中的20xx-x-xx更改为博客实际的成立时间,如:2011-1-01 

效果图:
代码作者:Tanky Woo

2条评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注