在制作wordpress主題期間,有的時候會用到【已經運行了多少天,共發表了多少篇原創文章,共收到了多少 條有效評論】等wordpress站點信息,接下來吾愛編程下面將羅列經常使用到的一些函數!
1、日志總數:
<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>
2、草稿數目:
<?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>
3、評論總數:
<?php echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?>
4、建站天數:
<?php echo floor((time()-strtotime("2012-11-22"))/86400); ?>
記得修改 2012-11-22 為你的建站日期
5、標簽總數:
<?php echo $count_tags = wp_count_terms('post_tag'); ?>
6、頁面總數:
<?php $count_pages = wp_count_posts('page'); echo $page_posts = $count_pages->publish; ?>
7、分類總數:
<?php echo $count_categories = wp_count_terms('category'); ?>
8、鏈接總數:
<?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); echo $link; ?>
9、用戶總數:
<?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; ?>
*