WordPress教程

WordPress 获取今天、昨天、本周、本月注册用户统计

阿里云

用 wordpress 获取今天、昨天、本周、本月注册用户统计时遇到个问题就是日期是 UTC 时间,那么如何转成 UTC+8 后再统计呢?

使用 CONVERT_TZ(`user_registered`,'+00:00','+08:00')

也想出现在这里?联系我们
创客主机
  1. add_action('wp_dashboard_setup', 'erphp_user_total_dashboard_widgets' );
  2. function erphp_user_total_dashboard_widgets() {
  3. if(current_user_can('administrator')){
  4. add_meta_box( 'erphp_user_total_widget', '注册统计', 'erphp_user_total_widget_function','dashboard', 'normal', 'core' );
  5. }
  6. }
  7.  
  8. function erphp_user_total_widget_function(){
  9. global $wpdb;
  10. $today_user = $wpdb->get_row("SELECT count(ID) as ct FROM $wpdb->users WHERE TO_DAYS(NOW())- TO_DAYS(CONVERT_TZ(`user_registered`,'+00:00','+08:00')) = 0");
  11. $yestoday_user = $wpdb->get_row("SELECT count(ID) as ct FROM $wpdb->users WHERE TO_DAYS(NOW())- TO_DAYS(CONVERT_TZ(`user_registered`,'+00:00','+08:00')) = 1");
  12. $week_user = $wpdb->get_row("SELECT count(ID) as ct FROM $wpdb->users WHERE YEARWEEK(date_format(CONVERT_TZ(`user_registered`,'+00:00','+08:00'),'%Y-%m-%d')) = YEARWEEK(now())");
  13. $month_user = $wpdb->get_row("SELECT count(ID) as ct FROM $wpdb->users WHERE DATE_FORMAT( CONVERT_TZ(`user_registered`,'+00:00','+08:00'), '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )");
  14.  
  15. echo '<div class="activity-block"><ul style="margin:0 -10px;overflow:hidden">';
  16. echo '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px);border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
  17. <div style="font-size:19px;margin-bottom:20px;">今日注册</div>
  18. <div><a style="font-size:16px" href="'.admin_url('users.php').'">'.($today_user?$today_user->ct:'0').' 用户</a></div>
  19. </li>';
  20. echo '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px);border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
  21. <div style="font-size:19px;margin-bottom:20px;">昨日注册</div>
  22. <div><a style="font-size:16px" href="'.admin_url('users.php').'">'.($yestoday_user?$yestoday_user->ct:'0').' 用户</a></div>
  23. </li>';
  24. echo '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px);border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
  25. <div style="font-size:19px;margin-bottom:20px;">本周注册</div>
  26. <div><a style="font-size:16px" href="'.admin_url('users.php').'">'.($week_user?$week_user->ct:'0').' 用户</a></div>
  27. </li>';
  28. echo '<li style="margin:0 10px 10px;float:left;width:calc(50% - 20px);border:1px solid #f0f0f1;padding:10px;box-sizing:border-box">
  29. <div style="font-size:19px;margin-bottom:20px;">本月注册</div>
  30. <div><a style="font-size:16px" href="'.admin_url('users.php').'">'.($month_user?$month_user->ct:'0').' 用户</a></div>
  31. </li>';
  32. echo '</ul></div>';
  33. }

WordPress 获取今天、昨天、本周、本月注册用户统计

已有 334 人购买
查看演示升级 VIP立刻购买

收藏
(1)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!