【发布时间】:2013-10-12 05:36:04
【问题描述】:
所以我有这个网站,你可以看到有两个菜单,一个在徽标旁边,另一个在右上角;
它们是在functions.php中使用此代码创建的;
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'extra-menu' => __( 'Extra Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
这是我使用菜单的代码;
<nav>
<?php wp_nav_menu(array( 'theme_location' => 'header-menu' ) ) ?>
</nav>
<nav id="ecommerce">
<?php wp_nav_menu( array( 'theme_location' => 'extra-menu' ) ); ?>
</nav>
并且菜单工作正常,除非您转到侧边栏中的类别,例如“博客”页面上的“文章”或“事件”;
http://www.ducklingfarm.com/blog/
博客页面是自定义帖子类型,为了使该类别正常工作,我在functions.php 中添加了一些代码,但此后菜单无法正常工作。那个代码是;
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('post','Blog');
$query->set('post_type',$post_type);
return $query;
}
}
所以我猜代码有问题。请帮我!我真的很感激。
最好, 宰恩
我通过将最后一个代码更改为这个来解决它;
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() && $query->is_main_query()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','Blog');
$query->set('post_type',$post_type);
return $query;
}
}
【问题讨论】:
-
菜单到底有什么问题?