WordPress 仪表盘界面添加百度统计数据展示模块

百度站长统计目前还是国内的主流网站统计,很多站长每天都会看看自己的网站数据,来查看自己的流量走向、访客来路、网站热门关键词、网站热门页面等等,看的最多的还是浏览量、访客数、IP数量。

这样你只要登陆你的 WordPress 站点后台就能看到百度统计的常规数据,是不是方便多了。

添加百度统计数据模块

WordPress 百度统计可以通过 function 函数实现,只需要在当前使用主题目录下的functions.php文件中添加以下代码即可:

//WordPress 仪表盘添加百度统计数据展示模块 - https://wpexp.cn/?p=86
function wpexp_add_dashboard_widgets() { 
wp_add_dashboard_widget('custom_help_widget', '百度统计数据', 'bdtj_dashboard_wpexp'); 
} 
add_action('wp_dashboard_setup', 'wpexp_add_dashboard_widgets' ); 
function bdtj_dashboard_wpexp() {
$body = array('header'=>array(
'username' => '百度统计账户',
'password' => '百度统计密码',
'token'=>'百度统计token',
'account_type'=>1
),'body'=>array(
'site_id'=>'百度统计站点ID',
'start_date'=>date("Y-m-d",strtotime("-1 day")),
'end_date'=>date("Y-m-d"),
'metrics'=>'pv_count,visitor_count,ip_count',
'method'=>'overview/getTimeTrendRpt'
));
$url='https://api.baidu.com/json/tongji/v1/ReportService/getData';//百度商业账号请求地址
$request = new WP_Http;
$result = $request->request( $url, array( 'method' => 'POST', 'body' => json_encode($body)) );
$rst=json_decode($result['body']);

$yest=$rst->body->data[0]->result->items[1][0];
$nowt=$rst->body->data[0]->result->items[1][1];
echo '日期&nbsp&nbsp&nbsp&nbsp浏览量&nbsp&nbsp&nbsp&nbsp访客数&nbsp&nbsp&nbsp&nbspIP数';
echo '';
echo '今日:&nbsp&nbsp&nbsp&nbsp';
for($i=0;$i