admin管理员组

文章数量:1291007

I solved the problem with the page, the correct answer is ptriek's comment below.

Well I'm having a bit of an odd problem here, wp_nav_menu works on all pages EXCEPT my category pages (probably my archive page too but there's no links on the website to the archive pages so that's alright).

Although there is archive.php in my theme files, this controls what is displayed on category, tag, archive, author, etc. pages.

I just don't understand why, since every page uses the same header.php to display wp_nav_menu, it won't show up for the category pages.

Am I overlooking something? I've been banging my head against my keyboard trying to figure this out and it just won't work!

Using a very simple code: <?php wp_nav_menu('container_class=menu-header&theme_location=primary'); ?>

I solved the problem with the page, the correct answer is ptriek's comment below.

Well I'm having a bit of an odd problem here, wp_nav_menu works on all pages EXCEPT my category pages (probably my archive page too but there's no links on the website to the archive pages so that's alright).

Although there is archive.php in my theme files, this controls what is displayed on category, tag, archive, author, etc. pages.

I just don't understand why, since every page uses the same header.php to display wp_nav_menu, it won't show up for the category pages.

Am I overlooking something? I've been banging my head against my keyboard trying to figure this out and it just won't work!

Using a very simple code: <?php wp_nav_menu('container_class=menu-header&theme_location=primary'); ?>

Share Improve this question edited Jan 14, 2014 at 17:32 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Dec 1, 2011 at 13:42 JaredJared 3,8453 gold badges35 silver badges58 bronze badges 1
  • 2 you could have look on wordpress/support/topic/… - see solution at the bottom (haven't tested it though) – ptriek Commented Dec 1, 2011 at 13:56
Add a comment  | 

4 Answers 4

Reset to default 6

I had the same problem, but with a newer version of Wordpress (3.7.1).

On pages with custom taxonomies of custom posts, the wp_nav_menu was not shown. The solution below worked for me.

in functions.php of the theme:

add_action( 'pre_get_posts', 'my_pre_get_posts' );
function my_pre_get_posts($query) {
  if ($query->get('post_type') === 'nav_menu_item') {
    $query->set('tax_query','');
  }
}

Implode's answer is right and helped me a lot. I tried to implement a hook (pre_get_posts) for avoiding to display posts of subcategories. My hook worked well despite of no more Nav-Menus.

So, when change the tax_query you have to avoid doing this for the query with post_type == 'nav_menu_item'.

Answer by Implode solve issue only if you are not using other queries like 'meta_key' even . I found complete solution here.

function fix_nav_menu( $query ) {
    if ( $query->get( 'post_type' ) === 'nav_menu_item' ) {
        $query->set( 'tax_query', '' );
        $query->set( 'meta_key', '' );
        $query->set( 'orderby', '' );
    }
}

add_action( 'pre_get_posts', 'fix_nav_menu' );

This one works for me. The answer found in this link on the second last post/comment: https://wordpress/support/topic/wp-nav-menu-dissapears-in-category-pages-1/?replies=15#post-1859168

Just need to add this on the theme's function.php file

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if(is_category() || is_tag()) {
    $post_type = get_query_var('post_type');
    if($post_type)
        $post_type = $post_type;
    else
        $post_type = array('nav_menu_item','post','articles');
    $query->set('post_type',$post_type);
    return $query;
    }
}

本文标签: categorieswpnavmenu not appearing for a couple pages