在制作WordPress主題的時候,往往會用到一些需要統(tǒng)計數(shù)量的地方,比如統(tǒng)計當前分類下面有多少篇文章,統(tǒng)計網(wǎng)站有多少注冊用戶等等,現(xiàn)整理如下,有需要的小伙伴可以保存一下。
1、日志總數(shù):
<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>
2、草稿數(shù)目:
<?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>
3、評論總數(shù):
<?php echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?>
4、成立時間:
<?php echo floor((time()-strtotime("20018"))/86400); ?>
5、標簽總數(shù):
<?php echo $count_tags = wp_count_terms('post_tag'); ?>
6、頁面總數(shù):
<?php $count_pages = wp_count_posts('page'); echo $page_posts = $count_pages->publish; ?>
7、分類總數(shù):
<?php echo $count_categories = wp_count_terms('category'); ?>
8、鏈接總數(shù):
<?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); echo $link; ?>
9、用戶總數(shù):
<?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users; ?>
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; ?>
新主題官方微信公眾號
掃碼關注新主題(XinTheme)官方公眾號,本站動態(tài)早知道。
發(fā)布本站最新動態(tài)(新主題發(fā)布、主題更新)和WordPress相關技術文章。