【发布时间】:2013-06-18 07:21:30
【问题描述】:
我正在使用此功能使我的自定义帖子类型“投资组合”显示在档案/类别/标签页面上(在 functions.php 中):
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array('post', 'portfolio'));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types'
问题是由于某种原因它使我的导航菜单消失了。这是导航菜单的代码(在 header.php 中):
<?php wp_nav_menu(array( 'theme_location' => 'primary', 'sort_column' => 'menu_order', 'menu_class' => 'nav-menu', 'container_class' => 'nav-menu',) ); ?>
知道我可以改变什么吗?
【问题讨论】:
-
控制台有错误吗?
-
代码中是否存在菜单的html?
-
菜单中的所有 html 都来自 wp_nav_menu(),然后由 css 设置样式。但是没有输出html。如果我删除函数“namespace_add_custom_types”,那么菜单就会恢复工作。
-
尝试注释掉该行:return $query;这会让菜单重新出现吗?
-
不,似乎只是上面的那一行在做。
标签: php wordpress function custom-post-type