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'); ?>
- 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
4 Answers
Reset to default 6I 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
版权声明:本文标题:categories - wp_nav_menu not appearing for a couple pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741514141a2382783.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论