相信很多博主喜欢在自己的博客上显示关于博客的一些信息,如:文章数量,评论数量,博客至今运行多少天等等,要实现它并不难,只需要把以下代码粘贴到适当的位置即可,至少格式,可以根据自己的需要再做调整。以下为代码:

<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更改为博客实际的成立时间,如:2010-1-01

转载请标明出处:小石头

本文地址:http://xiaostone.com/archives/2129.html