0

I'm trying to display a menu based on the page template AND the post category is used. I got it to work for the page template like this:

if (is_page_template('page-template-heroes.php')){ 
                        $primaryNav = wp_nav_menu( array( 'menu' => 'heroes', 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) ); 

But when I try it for a page template AND category, it's not working. Must be doing something wrong.

if (is_page_template('page-template-heroes.php') && in_category( 'skills-heroes' ) ){ 
                        $primaryNav = wp_nav_menu( array( 'menu' => 'heroes', 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) ); 
  • 2
    Pages don't typically have categories. Did you enabled categories for pages? Or are you using custom templates for another post type? – Jacob Peattie Jul 10 '19 at 12:00
  • Thanks for the reply! I'm trying to have a specific menu on pages with a specific page template and all post from a certain category. I didn't know about page categories. That could be another approach, thanks. – user1081953 Jul 10 '19 at 13:57
  • In that case you want to use || (or), not && (and). – Jacob Peattie Jul 10 '19 at 14:15
  • Amazing, thanks so much! – user1081953 Jul 10 '19 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.