0

Good day. I have some difficulties these days and i am a new at wordpress. I have task where I need to create different menu's on different category's, I had read a lot about it but still have some questions. I have created 8 category's with subcategories, and also 8 menu's including my subcategory's. In my template “html5blank-stable” category.php I am using this code down bellow

$this_category = get_category($cat); 
if (is_category( '2' ) || $this_category->category_parent == 2) { 
wp_nav_menu( array( 'menu_class' => 'menu','menu' => 'Visuomenei') );
}elseif (is_category( '16' ) || $this_category->category_parent == 16) { 
wp_nav_menu( array( 'menu_class' => 'menu', 'menu' => 'Studentams') );
}elseif (is_category( '27' ) || $this_category->category_parent == 27) { 
wp_nav_menu( array( 'menu_class' => 'menu', 'menu' => 'Personalui') );
}elseif (is_category( '54' ) || $this_category->category_parent == 54) { 
wp_nav_menu( array( 'menu_class' => 'menu', 'menu' => 'Kontaktai') );
}elseif (is_category( '63' ) || $this_category->category_parent == 63) { 
wp_nav_menu( array( 'menu_class' => 'menu', 'menu' => 'Kolegija') );
}

And this code works for me, but the problem is I am not sure this is good way doing it because I can't find much information maybe there are more easy methods. Any tip would be grateful. P.S sorry for english, but I hope someone understand my problem

0

This is a good way, Mardov. Another way is to specify the subcategory id in the in_category array which is easier method.

For example:

if (in_category( array( 2, 4, 5 ) ) { // 2, 4 & 5 can be a category or a subcategory
  wp_nav_menu( array( 'menu_class' => 'menu','menu' => 'Visuomenei') );
}

You may find it difficult to find the IDs of the categories, so install this plugin to RevealIDs

  • Thank you for reply! now i feel more easier when i know it is right way.Your method works great. – Mardov May 15 '15 at 10:28
  • Glad you liked it, Mardov! :) There are situations in WordPress where you have many solutions to a problem but finding the easier one maybe time consuming. – Manoj Kumar May 15 '15 at 10:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.