• Hi,

    I am trying to add different themes based on categories. I am aware of “category templates” and category-slug.php, category-ID.php did work for me for creating different colors based on categories. But my question is, if I need different headers for different categories. Is it possible?

    Suppose I have a site “www.example.com” with categories Automobile and Computer. Now when I click on Automobile category (menu), it should take me to “www.example.com/automobile” and that should again have headers like “bikes”, “cars”, “trucks” etc. Similarly with computers, it should have laptops, desktops, tablets etc., as menu’s.

    Can somebody guide me if this is possible with examples or tutorials? I am new to WordPress and php. Hence a little detailed explanation is much appreciated.

    Thanks,
    Praveen

Viewing 5 replies - 1 through 5 (of 5 total)
  • I suppose it is possible to copy the code you currently have in header.php and post that into custom-cat-head.php (making the edits your category requires) and instead of calling get_header() on your template you would just get_template_part() (https://codex.www.ads-software.com/Function_Reference/get_template_part) your custom header.

    Thread Starter praveen_khm

    (@praveen_khm)

    Thanks for the reply fwoan. Let me explain the problem. I have a free theme I am using and in admin panel, it already has options to create menu and submenu’s. Now if I follow your suggestion, should I discard the theme’s admin options altogether? The reason I am asking is the categories might change in future (might add, rename, or delete categories). Is it better to create a new theme from scratch in that case (since trying to edit the parent theme seems like it breaks).

    praveen_khm, I think I misunderstood your original post.

    Another fix without having to edit the theme too much would be to create as many menus as your site needs and then set up a php if statement to decide if it should be shown on your site.

    pseudocode:

    if ( is_category( 'my-custom-category' ) ) {
        INCLUDE RELEVANT MENU
    } else if ( is_category( 'my-other-custom-category' ) ) {
        INCLUDE RELEVANT MENU
    }

    Is this more in terms of what you were looking for
    ?

    Thread Starter praveen_khm

    (@praveen_khm)

    Thanks a lot. This is exactly what I was looking for.

    Let me try this code (might end up with 16-18 if statements). I am sure there is no particular limit in wordpress for the number of ifs and elseifs.

    Thanks again fwoan.

    Glad to help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Categorywise Theme’ is closed to new replies.