Ethos - Filterable Index

I have studied many of the posts related to the homepage filterable index. Let me ask the following questions and see if there might be child-theme alteration that could help:

(1) I seem to be running into a limit of 11 filter categories. If I add more than 11 it doesnā€™t appear. Is that normal, or do I have a problem with my categories?

(2) People are worried about the order of topics and so do I. Mine really arenā€™t alphabetical, but Iā€™ve been trying to reorder and rename my categories, so I suspect there are some latencies in my database. Question: Can the filter just be made to use the order by which you write down the categories in theme options?

(3) One option that seems like it would make people happy is that home page loads the posts without the filter active. If you turn off the filter the latest posts show irrespective of category. That seems to be what people want. Now after the index page loads the posts the filter is activated and available to downselect via the categories or even order by the ā€˜allā€™ option.

Hi @RocketSMS,

Thanks for reaching out :slight_smile:

  1. Are you referring to posts limit per category or the amount of category as filters? If itā€™s posts limit then please change it in Admin > Settings > Reading > Blog pages show at most. And there should be no limit to the amount of category as filters, please provide your siteā€™s URL and admin login credentials in the secure note in case itā€™s category filter related.

  2. It would require customizing the template, to do that, please check these first

https://theme.co/apex/forum/t/customizations-best-practices/205,
https://theme.co/apex/forum/t/how-to-upload-xtheme-to-child-theme/43246/2,

Then youā€™ll be working on this file

wp-content\themes\pro\framework\views\ethos\_index.php

and replace this line from that file

$categories = get_categories( array( 'include' => x_get_option( 'x_ethos_filterable_index_categories' ) ) );

with this line

$categories = get_categories( array( 'orderby' => 'name', 'include' => x_get_option( 'x_ethos_filterable_index_categories' ) ) );

Then that should order them by name.

  1. Do you mean that all posts should be displayed once the ā€œAllā€ filter is selected? Itā€™s not currently possible, the filterable index feature is grouping them by category regardless of selected. For it to work, it needs to re-query the entire page and or by use of Ajax request. Such feature is only available from existing plugins like Essential Grid or The Grid.

Hope these helps :slight_smile:

I added the secure note to the first post.

Letā€™s check #1 first.

Yes. I get less than the number of categories selected. I have done plenty of experiments and donā€™t yet see a pattern. I add the categories to the Category IDs

X > Theme Options > Ethos > Blog Options > Filterable Index (on) > Category IDS

In this case,

I added 13 and only 12 appear.

Hi @RocketSMS,

Would you mind granting an admin access? The current login has no capability to navigate the admin ad its functionality.

Thanks!

Oops. Sorry. I just fixed the admin rights on the new user so it has full rights. Sorry about that!

Hi @RocketSMS,

The category ID 1 is Uncategorized which is empty right now.

Iā€™ve changed this code:

$categories = get_categories( array( 'include' => x_get_option( 'x_ethos_filterable_index_categories' ) ) );

To this:

$categories = get_categories( array( 'hide_empty' => false, 'include' => x_get_option( 'x_ethos_filterable_index_categories' ) ) );

Then all the 13 categories are displaying fine now.

For more information, please take a look at this:

https://developer.wordpress.org/reference/functions/get_terms/

Cheers!

You guys are awesome for jumping in on this. And changing the code. Terrific service. Thanks.

It still acts a bit flakey, I got it to not show the right number of categories when I left off the category 1. But now itā€™s working fine. Perhaps itā€™s just a caching issue. Letā€™s call 1 done.

2). Iā€™m curious how the order of the filter items are set. I can probably learn to adapt. But my question is can we make a change to the child theme so the order of filters is the same order as the list we enter in X > Theme Options > Ethos > Blog Options > Filterable Index? Seems like that would be the cleanest solution for me and my colleagues posting on this topic.

Ji @RocketSMS,

  1. To achieve that, you can replace the code in your ethos/_index.php with this
<?php

// =============================================================================
// VIEWS/ETHOS/_INDEX.PHP
// -----------------------------------------------------------------------------
// Includes the index output.
// =============================================================================

$paged      = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$categories = get_categories( array( 'hide_empty' => false, 'include' => x_get_option( 'x_ethos_filterable_index_categories' ) ) );
$category_array = array();
$category_order =  explode(",",x_get_option( 'x_ethos_filterable_index_categories' ));
static $i = 1; $selected = ( $i == 1 ) ? 'class="selected"' : '';
foreach($categories as $category) {
        $category_array[array_search($category->cat_ID,$category_order)] = '<li><a href="#"'. $selected.'data-category-id="'.$category->term_id.'">'.$category->name.'</a></li>';
    }
    ksort($category_array);
?>

<ul class="option-set unstyled" data-option-key="filter">
  <li>
    <a href="#" class="x-index-filters cf">
      <span class="x-index-filter-label"><?php _e( 'Filter by Topic', '__x__' ); ?></span>
      <i class="x-icon-chevron-down" data-x-icon-s="&#xf078;"></i>
    </a>
    <ul class="x-index-filters-menu unstyled">
       
        <li><a href="#" <?php echo $selected; ?> data-category-id="0"><?php _e( 'All', '__x__' ); ?></a></li>

            <?php foreach($category_array as $category){ ?>

            <?php echo $category; ?>

        <?php $i++; ?>
      <?php } ?>
    </ul>
  </li>
</ul>

<div class="x-filterable-index">

  <?php

  foreach ( $categories as $category ) {

    static $j = 1;

    $selected = ( $j == 1 ) ? ' selected' : '';
    $accent   = x_ethos_category_accent_color( $category->term_id, '#333333' );
    $wp_query = new WP_Query( array( 'post_type' => 'post', 'paged' => $paged, 'cat' => $category->term_id, 'orderby' => 'title', 'order' => 'ASC' ) );

    echo '<div class="x-filterable-category-group' . $selected . '" data-category-id="' . $category->term_id . '">';

      if ( $wp_query->have_posts() ) :
        while ( $wp_query->have_posts() ) : $wp_query->the_post();
          x_get_view( 'ethos', 'content', get_post_format() );
        endwhile;
      endif;

      echo '<a href="' . get_category_link( $category->term_id ) . '" class="x-btn-filterable x-btn">See All ' . $category->name . ' Posts</a>';

    echo '</div>';

    wp_reset_query();

    $j++;

  }

  ?>

</div>

<script>

  jQuery('.x-index-filters').click(function(e) {
    e.preventDefault();
    var $this = jQuery(this);
    $this.parent().find('ul').slideToggle(600, 'xEaseOutExpo');
    if ( $this.hasClass('selected') ) {
      $this.removeClass('selected');
    } else {
      $this.addClass('selected');
    }
  });

  jQuery('.x-index-filters-menu a').click(function(e) {
    e.preventDefault();
    var $this       = jQuery(this);
    var $filter_cat = $this.data('category-id');
    jQuery('.x-index-filter-label').text($this.text());
    if ( ! $this.hasClass('selected') ) {
      $this.closest('ul').find('a').removeClass('selected');
      $this.addClass('selected');
    }
    jQuery('.x-filterable-category-group').each(function() {
      $this = jQuery(this);
      if ( $this.data('category-id') === $filter_cat ) {
        $this.css({ 'display' : 'block', 'visibility' : 'visible' });
        $this.find('.x-btn-filterable').css({ 'display' : 'block' });
      } else {
        $this.css({ 'display' : 'none', 'visibility' : 'hidden' });
      }
      if ( $filter_cat === 0 ) {
        $this.css({ 'display' : 'block', 'visibility' : 'visible' });
        $this.find('.x-btn-filterable').css({ 'display' : 'block' });
      }
    });
  });

</script>

Please note that this customization is outside the scope of support and that the code provided is simply a guide and to give you something to start with, if you need further customization you will need to do it yourself or consult a developer.

Thank you!

You guys are absolutely amazing. I followed what you did and it worked perfectly. This level of service is beyond what I expect. I also think this work will be observed by others and they will choose it. Hint, Hint. I see this as a new feature in upcoming releases.

Let me ask 3) above with a little more clarity.

If I turn off the filterable index I get a nice list of recent articles in the blog space. But I also like the filterable index, but do not prefer the articles that are initially loaded on the homepage with the filter turned on.

Is there a way to get the initial list as if the filter was not yet activated and then make the filter active. I guess I see this as the initial load on the homepage is unfiltered and then any use of the filter will apply its sort. I see other people asking this question as well with slightly different words.

I think you are going to tell me that change requires significant coding by replacing the filter with an alternative. But I thought I would ask my question a different way and confirm.

Thanks again!

Hello @RocketSMS,

You can only select which one to have for your blog index or homepage. You can either enabled the Filterable Index or just prefer to display the default blog index. Regretfully there is no way that you can display the default blog index and the filterable index on the same. Even with custom code that would not be possible because the blog index is a WP default query in displaying the blog index. The filterable index on the other hand uses a custom query which overrides the default query. In this query, the post items were group according by its category and order according by date.

Hope this explain it briefly.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.