通過這些簡(jiǎn)單有效的代碼來表達(dá)網(wǎng)站的相關(guān)統(tǒng)計(jì)數(shù)據(jù),大大方便了作者開發(fā)主題時(shí)的工作。
- 代碼來源:詳情
下面一一列表一些常用的統(tǒng)計(jì)信息代碼:
1、成立時(shí)間
<?php echo floor((time()-strtotime("2011-7-27"))/86400); ?>
2、文章總數(shù)
<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>
這里獲取的是默認(rèn)的文章,我們也可以獲取自定義類型文章的總數(shù),只需在wp_count_posts()
中添加自定義類型文章名稱就可以,代碼如下:
<?php $count_posts = wp_count_posts('portfolio'); echo $published_posts = $count_posts->publish;?>
3、評(píng)論總數(shù)
<?php echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?>
4、標(biāo)簽總數(shù)
<?php echo $count_tags = wp_count_terms('post_tag'); ?>
獲取自定義類型文章的標(biāo)簽修改標(biāo)簽分類法post_tag即可
5、頁面總數(shù)
<?php $count_pages = wp_count_posts('page'); echo $page_posts = $count_pages->publish; ?>
6、分類總數(shù)
<?php echo $count_categories = wp_count_terms('category'); ?>
獲取自定義類型文章的分類總數(shù),修改標(biāo)簽分類法category
即可
7、友情鏈接總數(shù)
<?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); echo $link; ?>
8、用戶總數(shù)
<?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users; ?>
9、草稿總數(shù)
<?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>
10、最后更新
<?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; ?>
這些只是針對(duì)單個(gè)網(wǎng)站的統(tǒng)計(jì)
測(cè)試