• I have been searching the forums for an answer to this one as I’m sure it will be here but have had no luck.

    I have a function that is pulling in a different custom menu on a category index depending on the category index you are viewing.

    if (is_category('Nights Out'))
    wp_nav_menu(array('theme_location' => 'nightsout','fallback_cb'=> ''));

    What I need is to also pull in the menu on the child category indexes.

    So if ‘Nights Out’ or child of ‘Nights Out’.

    What code do I need to use to pull in the children?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • [Code moderated as per the Forum Rules. Please use the pastebin]

    change 14 to the number of your parent category.

    Thread Starter fizzyfozzy

    (@fizzyfozzy)

    Thanks supervee but I can’t seem to get it to work.

    To give a bit more detail I have the following function in my functions.php file:

    function my_sub_menus() {
    	if (is_category('Nights Out'))
    	wp_nav_menu(array('theme_location' => 'nightsout','fallback_cb'=> ''));
    	elseif (is_category('Eat and Drink'))
    	wp_nav_menu(array('theme_location' => 'eatdrink','fallback_cb'=> ''));
    }

    And then this function is pulled in from my category loop also in the functions file:

    <div class="category_nav">
        <span>Sub-category:</span> <?php my_sub_menus(); ?>
    </div>

    How do I combine the function you provided with my my_sub_menus function?

    Thread Starter fizzyfozzy

    (@fizzyfozzy)

    The code you posted has been removed!?

    Could you repost?

    It’s probably not working because you’re missing a bracket for your if statements
    Try

    https://wordpress.pastebin.com/WViYXs7b

    Change 14 to the number of Nights Out category, and 15 to Eat and Drink category

    Thread Starter fizzyfozzy

    (@fizzyfozzy)

    Thanks again supervee but even with the brackets in it’s not working for me.

    I have tried placing the post_is_in_descendant_category function in my functions.php followed by my my_sub_menus function to include the if statements and then calling the my_sub_menus function in my category template category.php – this didn’t work.

    So I then tried the whole of your code as one directly in my category page. This also didn’t work at all and displayed nothing at all.

    With my first attempt the menu is displaying fine on the Nights Out category index, but on the child indexes Clubs and Live Music the menus are not showing.

    Is the issue because I am looking for this to show on a child category index rather than a single post?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘if category or child of category’ is closed to new replies.