Forums

Seperate/Different Template for Category and Sub-Cateogry (5 posts)

  1. abhishek99
    Member
    Posted 1 year ago #

    I have been trying to find a solution to this problem since the last 12 hours but didn't get a success.

    QUESTION: How can I get a different/seperate template for a category and for all the sub-categories under that category?
    For example:
    - I have CATEGORY 1. Under that Category I have SUB-CATEGORY 1, SUB-CATEGORY 2 and several other sub-categories.
    - Now I need to have a sperate template for Category 1 and for SUB-CATEGORY 1, SUB-CATEGORY 2 and other sub-categories..

    Is there an hack or a way to do that? I tried using an if statement in the category-category1.php (tcategory template file) to check if it has subcategories or something.but don't know how to divert it to the other tempalte after that.
    Can someone please help?

  2. Michael Fields
    Theme Wrangler
    Posted 1 year ago #

    Maybe this is what you are looking for?

    add_action( 'template_redirect', 'my_theme_child_category' );
    function my_theme_child_category() {
    	global $wp_query;
    	$obj = $wp_query->get_queried_object();
    	if( isset( $obj->category_parent ) && 94 === (int) $obj->category_parent ) {
    		require STYLESHEETPATH . '/category-94.php';
    		exit;
    	}
    }
  3. abhishek99
    Member
    Posted 1 year ago #

    Where do I place the Category Slug ?

  4. abhishek99
    Member
    Posted 1 year ago #

    Nevermind. Found a solution to this problem!! Thanks anyways :)

  5. xpert6
    Member
    Posted 1 year ago #

    abhishek can u pls share that solution .. i have a same problem thanks

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.