不同类别/页面/帖子的Wordpress自定义菜单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了不同类别/页面/帖子的Wordpress自定义菜单相关的知识,希望对你有一定的参考价值。

[register_nav_menus](http://codex.wordpress.org/Function_Reference/register_nav_menus,"register_nav_menus")
[wp_nav_menu](http://codex.wordpress.org/Function_Reference/wp_nav_menu,"wp_nav_menu")
[in_category](http://codex.wordpress.org/Function_Reference/in_category,"in_category")
[is_category](http://codex.wordpress.org/Function_Reference/is_category,"is_category")
  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. ?>

以上是关于不同类别/页面/帖子的Wordpress自定义菜单的主要内容,如果未能解决你的问题,请参考以下文章

Wordpress - 从自定义帖子类型中删除子菜单

如何:在wordpress中自定义帖子类型的自定义类别存档页面

wordpress 3.8.1 类别第 2 页错误 404 未找到 / 自定义帖子类型

如何获取在 Wordpress 中按类别过滤的自定义帖子类型的永久链接?

WordPress:如何使用 $wp_query 按类别过滤帖子?

自定义 wordpress 类别循环列表页面