第一步添加模块目录:
/ripro/inc/codestar-framework/options 目录下打开 options.theme.php,搜索 ‘lastpost’ => ‘最新文章展示’
并在 ‘lastpost’ => ‘最新文章展示’, 前添加 ‘census’ =>’统计模块’,
必须包括上引号及逗号如下图:
第二步:/ripro/parts/home-mode目录下新建“census.php”,并添加如下代码
<?php $mode_census = _cao('mode_census'); $count_posts = wp_count_posts(); $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); ob_start(); ?> <divclass="section text-center pb-0"style="padding-top:20px; height:75px;"> <divclass="container"> <divclass="alert alert-modern alert-dark"> <divclass="alert-content"> <spanclass="type_icont_2"><iclass="fa fa-bell-o"></i> 博主统计 </span> <spanclass="description-17codesign"> <p> 资源总数:<?php echo $published_posts = $count_posts->publish;?>个 ๑ 注册用户:<?php echo $users; ?>位 ๑ 本周更新:<?php echo get_week_post_count(); ?>篇 ๑ 今日更新:<?php echo WeeklyUpdate();?>篇 </p> </span> </div> </div> </div> </div>
第三步:主题目录打开 functiond.php,在最后一行后面添加
// 每周更新 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; } // 每周日新 function WeeklyUpdate() { $today = getdate(); $query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"]); $postsNumber = $query->found_posts; echo $postsNumber;
添加代码后添加 ‘统计模块’显示,进入后台-首页布局-重置当前分区(千万别手贱点了重置全部)