How to display Wordpress categories on subcategories page?

Ok, let me start by telling you my purpose, then you can see an example below that makes more sense. I'm trying to create a simple filter with categories, so to speak. I am creating a simple custom post type called Cars and it will have a field to display and describe all cars. Now I am showing a custom post type through a loop and filters them by assigning them to specific categories and displaying them in the conditionals of category.php.

So, I have a HONDA category and 3 subcategories of this category:

  • Accord
  • Civic
  • Prelude

Now when I am on the Cars page it will display the custom post type ALL Categories and on the left side there will be a sidebar with all CARS categories like HONDA - TOYOTA - NISSA

When I click on a category that is a car brand on the left, it displays all the custom post types that are assigned to that specific category, and in the sidebar where now categories are displayed, which will only show in HONDA categories and that is Sub-Categories

NOW PROBLEM: When I click on a HONDA subcategory such as Accord, the sidebar displaying all vehicle categories related to that subcategory no longer appears when it should.

CLICK HERE FOR EXAMPLE (this should make things a lot clearer)

And here is the logic I'm using to filter which categories appear in the sidebar based on which category it is in.

<?php if (is_category('Honda') ) : ?>

    <?php $args = array(
    'orderby'            => 'name',
    'order'              => 'ASC',
    'style'              => 'list',
    'show_count'         => 1,
    'hide_empty'         => 1,
    'use_desc_for_title' => 1,
    'child_of'           => 5,
    'hierarchical'       => 1,
    'title_li'           => __( 'Categories' ),
    'show_option_none'   => __( 'No categories' ),
    'number'             => null,
    'echo'               => 1,
    'taxonomy'           => 'category',
    'walker'             => null
); ?>

<?php wp_list_categories( $args ); ?>

<?php else : ?>
<p>This is some generic text to describe all other category pages.</p>
<?php endif; ?>

      

+3


source to share


1 answer


There is also a Wordpress in_category function

http://codex.wordpress.org/Function_Reference/in_category



So your code should look something like this:

<?php if (is_category('Honda') || in_category('Honda') ) : ?>

      

+1


source







All Articles