当查询字符串包含某些参数时,wp_nav_menu()返回空 [英] wp_nav_menu() returns empty when query string contains certain parameters

查看:68
本文介绍了当查询字符串包含某些参数时,wp_nav_menu()返回空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在wp_nav_menu()中添加了导航菜单,这让我感到奇怪.

I'm having this strange glitch with a nav menu obtianed through wp_nav_menu().

该函数在每种情况下均会正确返回菜单,但ARCHIVE请求中的查询字符串包含'cat'参数时除外.例如:

The function returns the menu correctly in every situation except for when the query string in an ARCHIVE request includes the 'cat' parameter. For example:

我有一个自定义帖子类型故事",其存档仅为myhomeurl.com/story.对于此页面,wp_nav_menu()会正确返回菜单,并按原样显示.

I have a custom post type 'Stories' for which the archive is just myhomeurl.com/story. For this page, wp_nav_menu() will return the menu correctly and as such will display as it should.

但是,如果我只想查看具有特定类别的故事(即myhomeurl.com/story/?cat=5),则wp_nav_menu()将不会返回任何内容.这不是显示问题,只是wp_nav_menu()不会返回任何标记.

But if I want to see just the stories with a certain category (i.e. myhomeurl.com/story/?cat=5), then wp_nav_menu() will not return anything. It's not a display issue, it is just that wp_nav_menu() will not return any markup.

我不知道是什么原因造成的,我只能弄清这些情况:在存档中,在查询字符串中设置了category参数.

I have no idea what could be causing this, all I have been able to figure out is those conditions: in an archive with the category parameter set in the query string.

只要有相关性,我就使用响应式"主题的自定义子主题.

Just in case it is relevant, I am using a customized child theme of the 'Responsive' theme.

不幸的是,这是本地版本,所以我不能真正链接到网站本身,我希望这不是问题.

Unfortunately this is a local build so I can't really link to the site itself, I hope that is not an issue.

在此先感谢您的帮助.

推荐答案

我也遇到了同样的问题.自定义帖子类型似乎与您的导航混在一起.如果您用此代码包装导航代码,它应该可以工作:

I was having this same issue too. It seems that the custom post types are getting mixed up with your navigation. If you wrap your navigation code with this, it should work:

<?php   $backup = $wp_query;
        $wp_query = NULL;
        $wp_query = new WP_Query(array('post_type' => 'post')); 

        //nav code goes here

        $wp_query = $backup; ?>

这篇关于当查询字符串包含某些参数时,wp_nav_menu()返回空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆