WordPress.org

Forums

Categorywise Theme (6 posts)

  1. praveen_khm
    Member
    Posted 3 years ago #

    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

  2. fwoan
    Member
    Posted 3 years ago #

    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() (http://codex.wordpress.org/Function_Reference/get_template_part) your custom header.

  3. praveen_khm
    Member
    Posted 3 years ago #

    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).

  4. fwoan
    Member
    Posted 3 years ago #

    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
    ?

  5. praveen_khm
    Member
    Posted 3 years ago #

    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.

  6. fwoan
    Member
    Posted 3 years ago #

    Glad to help.

Topic Closed

This topic has been closed to new replies.

About this Topic