Category Specific Featured Posts

Hello!

How do I create category specific for the “Post Slider - Archive” display?

I have an automotive site and I am displaying different car COMPANIES in different categories.

Chevy http://kennebell.net/category/press/chevy/
Dodge http://kennebell.net/category/press/dodge/
Ford http://kennebell.net/category/press/ford/

Within each category I have a subcategory for the MODELS

CATEGORY Ford: http://kennebell.net/category/press/ford/
SUBCATEGORY: http://kennebell.net/category/press/ford/mustang/

Within each subcategory I have…you guessed it… another subcategory for MODEL YEAR/ENGINE TYPE.

SUBCATEGORY: http://kennebell.net/category/press/ford/mustang/
SUB-SUBCATEGORY: http://kennebell.net/category/press/ford/ford-gt500-supercar/
SUB-SUBCATEGORY: http://kennebell.net/category/press/ford/mustang-shelby-gt500/

I would like each “Post Slider for Archives” to be category specific.

Maybe I customize the category ID and connect with a specific page?

As always any help is…helpful! [And Appreciated!]

Hello There,

Thanks for writing in! This particular customization request is outside the scope of our support as this is not related to an issue with the theme and instead has to do with your customization of it. As such, you will need to investigate this particular issue on your own or seek help from a developer should you not feel comfortable making these changes yourself.

We can give you a guide how you can start to modify the theme to cater this feature which would display the post to be category specific. You may insert your code modifications in the _post-slider.php file. Assuming that you have your child theme active and ready, please follow the following steps below:
1] Using Notepad or TextEdit or Sublime Text or any text editor, please create a new file in your local machine.
2] Insert the following code into that new file

<?php

// =============================================================================
// VIEWS/ETHOS/_POST-SLIDER.PHP
// -----------------------------------------------------------------------------
// Outputs the post slider that appears at the top of the blog.
// =============================================================================

$is_blog    = is_home();
$is_archive = is_category() || is_tag();

if ( $is_blog || $is_archive ) :

  if ( $is_blog ) {
    $info = array( 'blog', NULL, NULL, '_x_ethos_post_slider_blog_display' );
  } elseif ( $is_archive ) {
    $type = ( is_category() ) ? 'cat' : 'tag_id';
    $info = array( 'archive', $type, get_queried_object_id(), '_x_ethos_post_slider_archives_display' );
  }

  $slider_enabled = x_get_option( 'x_ethos_post_slider_' . $info[0] . '_enable' ) == '1';
  $count          = x_get_option( 'x_ethos_post_slider_' . $info[0] . '_count' );
  $display        = x_get_option( 'x_ethos_post_slider_' . $info[0] . '_display' );

  $blog_slider_is_enabled    = $slider_enabled && $is_blog;
  $archive_slider_is_enabled = $slider_enabled && $is_archive;
  $is_enabled                = $blog_slider_is_enabled || $archive_slider_is_enabled;

  switch ( $display ) {
    case 'most-commented' :
      $args = array(
        'post_type'      => 'post',
        'posts_per_page' => $count,
        'orderby'        => 'comment_count',
        'order'          => 'DESC',
        $info[1]         => $info[2]
      );
      break;
    case 'random' :
      $args = array(
        'post_type'      => 'post',
        'posts_per_page' => $count,
        'orderby'        => 'rand',
        $info[1]         => $info[2]
      );
      break;
    case 'featured' :
      $args = array(
        'post_type'      => 'post',
        'posts_per_page' => $count,
        'orderby'        => 'date',
        'meta_key'       => $info[3],
        'meta_value'     => 'on',
        'ignore_sticky_posts'	=> true
      );
      break;
  }

  ?>

  <?php if ( $is_enabled ) : ?>

    <div class="x-flexslider x-post-slider">
      <ul class="x-slides">

        <?php if ( is_category() ) : ?>
          
            <?php 
              $this_category = get_category(get_query_var('cat'));


                $categories = get_categories( array(
                    'orderby' => 'name',
                    'parent'  => $this_category->term_id
                ) );
                
                $subcategories = '';
                foreach ( $categories as $category ) {
                    $subcategories .= $category->term_id;
                }
                $cat_args = array('cat' => $subcategories);
                print_r($cat_args);
                $args = wp_parse_args( $cat_args, $args );
            ?>

        <?php endif; ?>

        <?php $wp_query = new WP_Query( $args ); ?>

        <?php if ( $wp_query->have_posts() ) : ?>
          <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

            <li class="x-slide">
              <article <?php post_class( 'x-post-slider-entry' ); ?> style="<?php echo x_ethos_entry_cover_background_image_style(); ?>">
                <a href="<?php the_permalink(); ?>">
                  <div class="cover">
                    <div class="middle">
                      <span class="featured-meta"><?php echo x_ethos_post_categories(); ?> / <?php echo get_the_date( 'F j, Y' ); ?></span>
                      <h2 class="h-featured"><span><?php x_the_alternate_title(); ?></span></h2>
                      <span class="featured-view"><?php _e( 'View Post', '__x__' ); ?></span>
                    </div>
                  </div>
                </a>
              </article>
            </li>

          <?php endwhile; ?>
        <?php endif; ?>

        <?php wp_reset_query(); ?>

      </ul>
    </div>

    <script>
      jQuery(window).load(function() {
        jQuery('.x-post-slider').flexslider({
          controlNav   : false,
          selector     : '.x-slides > li',
          prevText     : '<i class="x-icon-chevron-left" data-x-icon="&#xf053;"></i>',
          nextText     : '<i class="x-icon-chevron-right" data-x-icon="&#xf054;"></i>',
          animation    : 'fade',
          smoothHeight : true,
          slideshow    : true
        });
      });
    </script>

  <?php endif; ?>

<?php endif; ?>

3] Save the file named as _post-slider.php
4] Upload this file to your server in the child theme’s folder wp-content/themes/x-child/framework/views/ethos/

Please understand that the code above is just an example code for you to start with. You may have to do more conditions to display sub categories and sub sub categories.

As this is all custom development, we won’t be able to assist further. Custom development is outside the scope of our support. We’re happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation.

Hope this helps.

I had the same problem with different categories but without the need of subcategories.
So i reduced your suggested code extension to this:

    <?php if ( is_category() ) : ?>
        <?php 
        	$this_category = get_category(get_query_var('cat'));
	$cat_args = array('cat' => $this_category->term_id);
	$args = wp_parse_args( $cat_args, $args );
      ?>
    <?php endif; ?>

It seems to work and maybe it is usefully for other with the same problem.
But please correct me if this code could be making any trouble?

It would be nice to have the option that no slider appears if theres is no featured post.

Hi there,

As long as it works then it should be okay and noted. I’ll add that as feature request :slight_smile:

Thanks!

I believe I added this on my website, and it worked!

However it’s been a few months, and I don’t recall where I did it in my site.

How do I get rid of the sliders on the category pages?

Hello There,

Thanks for updating this thread.

How do I get rid of the sliders on the category pages?

We would loved to know if this has work for you. Thank you.

This worked perfectly!

We are delighted to assist you with this.

Cheers!