Posted By

hell0world on 12/13/12


Tagged

menu wordpress category wp menus custom


Versions (?)

Wordpress Custom Menu For Different Category/Page/Post


 / Published in: PHP
 

  1. <?php
  2.  
  3. // add the following to wp theme function.php
  4. register_nav_menus( array(
  5. 'primary-menu' => 'main menu',
  6. 'marketing-menu' => 'marketing menu',
  7. 'shopping menu' => 'shopping menu',
  8. 'technology menu' => 'technology menu',
  9. 'recreation menu' => 'recreation menu',
  10. ) );
  11.  
  12. add_action( 'init', 'register_nav_menus' );
  13. ?>
  14.  
  15. <?php
  16. // add following to where you want the menu share, in my case, hearder.php
  17. <?php
  18. if((has_nav_menu('marketing-menu') and !is_home() and is_category(array(5,6,8,9,10,11,12,13,14))) or (has_nav_menu('marketing-menu') and !is_home() and in_category(array(5,6,8,9,10,11,12,13,14)))) {
  19. wp_nav_menu(array(
  20. 'theme_location' => 'marketing-menu',
  21. 'container' => '',
  22. 'menu_id' => 'primary-nav',
  23. 'container_class' => 'main-menu',
  24. 'menu_class' => 'nav'
  25. ));
  26. }
  27. else(has_nav_menu('primary-menu')){
  28. wp_nav_menu(array(
  29. 'theme_location' => 'primary-menu',
  30. 'container' => '',
  31. 'menu_id' => 'primary-nav',
  32. 'container_class' => 'main-menu',
  33. 'menu_class' => 'nav'
  34. ));
  35.  
  36. ?>

Report this snippet  

You need to login to post a comment.