NOISE知识效率集
🗿

wordpress统计全站总访问量/今日总访问量/当前是第几个访客

 
notion image
functions.php加入
/** 统计全站总访问量/今日总访问量/当前是第几个访客 * @return [type] [description] */ function wb_site_count_user(){ $addnum = rand(5,10); //每个访客增加的访问数 5 - 10的随机数 session_start(); $date = date('ymd',time()); if(!isset($_SESSION['wb_'.$date]) && !$_SESSION['wb_'.$date]){ $count = get_option('site_count'); if(!$count || !is_array($count)){ $newcount = array( 'all' => 8377670, 'date' => $date, 'today' => $addnum ); update_option( 'site_count', $newcount ); }else{ $newcount = array( 'all' => ($count['all']+$addnum), 'date' => $date, 'today' => ($count['date'] == $date) ? ($count['today']+$addnum) : $addnum ); update_option( 'site_count', $newcount ); } $_SESSION['wb_'.$date] = $newcount['today']; } return; } add_action('init', 'wb_site_count_user'); //输出访问统计 function wb_echo_site_count(){ session_start(); $sitecount = get_option('site_count'); $date = date('ymd',time()); echo '<p>总访问量:<span style="color:red">'.absint($sitecount['all']).'</span>    今日访问量:<span style="color:red">'.absint($sitecount['today']).'</span>    您是今天第:<span style="color:red">'.absint($_SESSION['wb_'.$date]).'</span> 个访问者</p>'; }
调用显示
wb_echo_site_count();
badge