时间:2023-08-13 21:42:01 | 来源:网站运营
时间:2023-08-13 21:42:01 来源:网站运营
WordPress独立站信息统计常用代码:文章数、评论数、建站天数、浏览量等:大家使用WordPress建立跨境独立站后,如果想了解网站运营维护的情况,少不了通过数据进行统计分析。<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>
<?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>
<?php echo $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->comments”);?>
<?php echo floor((time()-strtotime(“2018-04-20”))/86400); ?>
代码中日期改成你网站开始运行日期,通过倒叙来生成天数<?php echo $count_tags = wp_count_terms(‘post_tag’); ?>
<?php $count_pages = wp_count_posts(‘page’); echo $page_posts = $count_pages->publish; ?>
<?php echo $count_categories = wp_count_terms(‘category’); ?>
<?php $link = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = ‘Y'”); echo $link; ?>
<?php $users = $wpdb->get_var(“SELECT COUNT(ID) FROM $wpdb->users”); echo $users; ?>
<?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; ?>
//WordPress获取网站浏览量总数function all_view() /*调用的函数名*/{global $wpdb;$count=0;$views= $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key='views'");foreach($views as $key=>$value){$meta_value=$value->meta_value;if($meta_value!=' '){$count+=(int)$meta_value;}}return $count;}
再在需要显示的地方添加以下php代码<?php echo all_view(); ?>
关键词:评论,浏览,文章,信息,独立,统计