本文最后更新于 2020-11-20,已超过 365 天未更新,内容可能已失效。
[tip_success]虽然油条说: 这里为静态数组展示 为什么不用动态呐 因为很多人的站没有那么多真实数据。但是数据一直都是固定不变的,太有点说不去过了。计划书之家认为还是做个动态的要好一点,代码在实际统计有增加。[/tip_success]
好了不多说,直接上教程!
第一步:往fucntions.php添加如下代码
[rihide]
/*
* ------------------------------------------------------------------------------
* 每周更新的文章数量www.jhshome.top
* ------------------------------------------------------------------------------
*/
function get_week_post_count()
{
$date_query = array(
array(
'after'=>'1 week ago'
)
);$args = array(
'post_type' => 'post',
'post_status'=>'publish',
'date_query' => $date_query,
'no_found_rows' => true,
'suppress_filters' => true,
'fields'=>'ids',
'posts_per_page'=>-1
);
$query = new WP_Query( $args );
return $query->post_count;
}
/*
* ------------------------------------------------------------------------------
* 每日更新的文章数量www.jhshome.top
* ------------------------------------------------------------------------------
*/
function WeeklyUpdate()
{
$today = getdate();
$query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"]);
$postsNumber = $query->found_posts;
return $postsNumber;
}
[/rihide]
第二步:文件template-parts\home \vipinfo.php的代码107-133
// 这里为静态数组展示 为什么不用动态呐 因为很多人的站没有那么多真实数据
$coldata2 = [
[
'color'=>'text-warning',
'icon'=>'mdi-account-group',
'title'=>'1388+',
'desc'=>'会员总数(位)',
],
[
'color'=>'text-primary',
'icon'=>'mdi-cloud-download',
'title'=>'40720+',
'desc'=>'资源总数(个)',
],
[
'color'=>'text-info',
'icon'=>'mdi-timelapse',
'title'=>'513+',
'desc'=>'本周发布(个)',
],
[
'color'=>'text-success',
'icon'=>'mdi-monitor-multiple',
'title'=>'91080+',
'desc'=>'稳定运行(天)',
],
];
替换为
[rihide]
// 这里为静态数组展示 为什么不用动态呐 因为很多人的站没有那么多真实数据
$coldata3 =[
[$week=get_week_post_count()],
[$publish_posts = wp_count_posts()->publish],
[$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users")+2000],
[$blogtime =floor((time()-strtotime("2019-02-05"))/86400)],
];
$coldata2 = [
[
'color'=>'text-warning',
'icon'=>'mdi-account-group',
'title'=>$users,
'desc'=>'会员总数(位)',
],
[
'color'=>'text-primary',
'icon'=>'mdi-cloud-download',
'title'=>$publish_posts,
'desc'=>'资源总数(个)',
],
[
'color'=>'text-info',
'icon'=>'mdi-timelapse',
'title'=>$week,
'desc'=>'本周发布(个)',
],
[
'color'=>'text-success',
'icon'=>'mdi-monitor-multiple',
'title'=>$blogtime,
'desc'=>'稳定运行(天)',
],
];
[/rihide]
除非注明,子佩工作室 文章均为原创,转载请以链接形式标明本文地址。



登录后即可发表评论
全部评论 (0)