Hello,嗨,大家好,我是哈喽猿。
这里是哈喽猿网
今天推送的是wordpress教程的文章,感谢您宝贵的时间阅读
WordPress进阶教程目录:
5.WordPress 数据库清理优化WP-Optimize
25.WordPress 自动采集发布 长腿蜘蛛 WP-CTspider
最近,一些学生询问哈喽猿如何实现网站的基本信息统计功能,包括文章数量、评论数量、建站天数等。在Vango博客中查找相应的WordPress站点统计功能代码,需要好友添加。以下只给出了相应的统计函数,最终的风格将取决于其他人。
1、日志总数:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #000088;">$count_posts</span> <span style="color: #339933;">=</span> wp_count_posts<span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$published_posts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$count_posts</span><span style="color: #339933;">-></span><span style="color: #004000;">publish</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?></span>
2、草稿数目:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #000088;">$count_posts</span> <span style="color: #339933;">=</span> wp_count_posts<span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$draft_posts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$count_posts</span><span style="color: #339933;">-></span><span style="color: #004000;">draft</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?></span>
3、评论总数:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-></span><span style="color: #004000;">get_var</span><span style="color: #009900;">(</span><span style="color: #0000ff;">"SELECT COUNT(*) FROM <span style="color: #006699; font-weight: bold;">$wpdb->comments</span>"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?></span>
4、建站天数:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">floor</span><span style="color: #009900;">(</span><span style="color: #009900;">(</span><span style="color: #990000;">time</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">-</span><span style="color: #990000;">strtotime</span><span style="color: #009900;">(</span><span style="color: #0000ff;">"2012-11-22"</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">86400</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?></span>
5、标签总数:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$count_tags</span> <span style="color: #339933;">=</span> wp_count_terms<span style="color: #009900;">(</span><span style="color: #0000ff;">'post_tag'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?></span>
6、页面总数:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #000088;">$count_pages</span> <span style="color: #339933;">=</span> wp_count_posts<span style="color: #009900;">(</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$page_posts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$count_pages</span><span style="color: #339933;">-></span><span style="color: #004000;">publish</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?></span>
7、分类总数:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$count_categories</span> <span style="color: #339933;">=</span> wp_count_terms<span style="color: #009900;">(</span><span style="color: #0000ff;">'category'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?></span>
8、链接总数:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-></span><span style="color: #004000;">get_var</span><span style="color: #009900;">(</span><span style="color: #0000ff;">"SELECT COUNT(*) FROM <span style="color: #006699; font-weight: bold;">$wpdb->links</span> WHERE link_visible = 'Y'"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$link</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?></span>
9、用户总数:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #000088;">$users</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-></span><span style="color: #004000;">get_var</span><span style="color: #009900;">(</span><span style="color: #0000ff;">"SELECT COUNT(ID) FROM <span style="color: #006699; font-weight: bold;">$wpdb->users</span>"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$users</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?></span>
10、最后更新:
<span style="color: #000000; font-weight: bold;"><?php</span> <span style="color: #000088;">$last</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-></span><span style="color: #004000;">get_results</span><span style="color: #009900;">(</span><span style="color: #0000ff;">"SELECT MAX(post_modified) AS MAX_m FROM <span style="color: #006699; font-weight: bold;">$wpdb->posts</span> WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><span style="color: #000088;">$last</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">(</span><span style="color: #0000ff;">'Y-n-j'</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">(</span><span style="color: #000088;">$last</span><span style="color: #009900;">[</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">]</span><span style="color: #339933;">-></span><span style="color: #004000;">MAX_m</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$last</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?></span>
0 评论