• I have successfully

    1. Created a page displaying posts on a category
    2. Created a custom field to display menu based on that page

    But when I click on a post of that category, the menu comes back to the default one.

    What I try to achieve is, all posts in that category and subcategories will show the menu that I designed for the category and subs. Should I use conditional tags or something?

    Any help is appreciated…

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter inrajaka

    (@inrajaka)

    Is there anyone around?

    Yes, conditional tag in_category() is a variant to use.

    Thread Starter inrajaka

    (@inrajaka)

    Thanks… I will try that. Is there any way to declare the category and its subcategories? Adding numbers is hard

    $special_cats[] = 1; // 1 is ID of parent cat
    $args = array(
        'child_of' => $special_cats[0];
    );
    $categories = get_categories($args);
    foreach($categories as $category) {
        $special_cats[] = $category->cat_ID;
    }
    (in_category($special_cats) || is_category($special_cats)) ? $theme_location = 'special' : $theme_location = 'default';
    wp_nav_menu(array(
        'theme_location' => $theme_location
    ));

    Example

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Post template based on categories’ is closed to new replies.