RiPro主题-添加文章会员数量统计代码模块

RiPro主题-添加文章会员数量统计代码模块

主题

第一步添加模块目录:

/ripro/inc/codestar-framework/options 目录下打开 options.theme.php,搜索  ‘lastpost’ => ‘最新文章展示’

并在 ‘lastpost’ => ‘最新文章展示’,   前添加   ‘census’  =>’统计模块’,

必须包括上引号及逗号如下图:

RiPro主题

第二步:/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(); ?>
<div class="section text-center pb-0" style="padding-top:20px; height:75px;">
  <div class="container">
    <div class="alert alert-modern alert-dark">
      <div class="alert-content">
        <span class="type_icont_2"><i class="fa fa-bell-o"></i> 博主统计 </span>
        <span class="description-17codesign">
          <p>  资源总数:<?php echo $published_posts = $count_posts->publish;?>&#3665;   注册用户:<?php echo $users; ?>&#3665;   本周更新:<?php echo get_week_post_count(); ?>&#3665;   今日更新:<?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;

添加代码后添加 ‘统计模块’显示,进入后台-首页布局-重置当前分区(千万别手贱点了重置全部)

分享到 :
相关推荐

发表评论

登录... 后才能评论