统计访问量代码:
/**
* 统计全站总访问量/今日总访问量/当前是第几个访客
* @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>';
}
* 统计全站总访问量/今日总访问量/当前是第几个访客
* @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>';
}
代码使用方法:
1、将以上代码添加到wordpress主题根目录下的funciton.php函数文件后面;
2、在需要调用的地方输入。
<?php wb_echo_site_count(); ?>
上述代码来自西部盒子博客。