最新公告
  • 欢迎您光临杂话集,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!
  • WordPress Ripro 主题的分类列表页有筛选功能,但是默认会显示全部一级分类。如果我们想在某一个分类下,只显示指定的几个分类进行筛选,就需要进行简单的修改。

    首先,我们打开 /wp-content/themes/ripro/inc/codestar-framework/options 目录下的 taxonomy.theme.php 在下方代码

        array(
            'id'      => 'thumbnail_px_custom',
            'type'    => 'dimensions',
            'title'   => '自定义文章缩略图宽高,0为使用全局默认',
            'default' => array(
                'width'  => '0',
                'height' => '0',
                'unit'   => 'px',
            ),
        ),

    之后插入

        array(
          'id'          => 'filter_bar_include',
          'type'        => 'select',
          'title'       => '要在分类页面筛选栏中显示的分类',
          'placeholder' => '选择分类',
          'options'     => 'categories',
          'multiple'    =>  true,
          'sortable'    =>  true,
          'chosen'      =>  true,
          'ajax'        =>  true,
          'query_args'  => array(
             'hide_empty'  => false,
           ),
        ),

    再打开 /wp-content/themes/ripro/parts 目录下的 filter-bar.php 将下方代码

    <?php 
        if (!_cao('is_filter_bar')) :
        $cat_ID = (is_category()) ? get_query_var('cat') : 0 ;
        $cat_orderby = _cao('is_filter_item_cat_orderby','id');
        ///////////S CACHE ////////////////
        if (CaoCache::is()) {
          $_the_cache_key = 'ripro_filter_cat_'.$cat_orderby;
          $_the_cache_data = CaoCache::get($_the_cache_key);
          if(false === $_the_cache_data ){
              $_the_cache_data = get_terms('category', array('hide_empty' => 0,'parent' => 0,'orderby' =>$cat_orderby,'order' => 'DESC')); //缓存数据
              CaoCache::set($_the_cache_key,$_the_cache_data);
          }
          $categories = $_the_cache_data;
        }else{
          $categories = get_terms('category', array('hide_empty' => 0,'parent' => 0,'orderby' =>$cat_orderby,'order' => 'DESC')); //缓存数据
        }
        ///////////S CACHE ////////////////
    ?>

    替换为

    <?php 
        if (!_cao('is_filter_bar')) :
        $cat_ID = (is_category()) ? get_query_var('cat') : 0 ;
        $cat_orderby = _cao('is_filter_item_cat_orderby','id');
    
        $cat_ID  = get_query_var('cat');
        $cat_include_id = get_term_meta( $cat_ID, 'filter_bar_include', true ); 
        ///////////S CACHE ////////////////
        if (CaoCache::is()) {
          $_the_cache_key = 'ripro_filter_cat_'.$cat_orderby;
          $_the_cache_data = CaoCache::get($_the_cache_key);
          if(false === $_the_cache_data ){
              $_the_cache_data = get_terms('category', array('hide_empty' => 0,'parent' => 0,'orderby' =>$cat_orderby,'order' => 'DESC','include'=>$cat_include_id)); //缓存数据
              CaoCache::set($_the_cache_key,$_the_cache_data);
          }
          $categories = $_the_cache_data;
        }else{
          $categories = get_terms('category', array('hide_empty' => 0,'parent' => 0,'orderby' =>$cat_orderby,'order' => 'DESC','include'=>$cat_include_id)); //缓存数据
        }
        ///////////S CACHE ////////////////
    ?>

    最后,只需要到相应分类下选择希望显示的分类即可,可多选。