WordPress wp_nav_menu打破了我的循环

时间:2012-07-25 03:56:19

标签: wordpress loops

当我尝试更新一直使用wp_list_pages来使用wp_nav_menu的旧主题时,循环显示我的帖子和页面中断。我尝试过不同的实现,包括:

http://thinkvitamin.com/code/getting-started-with-wordpress-custom-menus/

http://wpfirstaid.com/2010/07/upgrade-wp_list_pages-to-wp_nav_menu/

来自WordPress codex的基本实现。

对functions.php进行更改对循环没有影响,但是当我向模板中添加任何版本的wp_nav_menu时,它会阻止调用post或page的循环工作。我的循环是:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

如果我使用query_posts,则会显示内容,但有关循环的内容与wp_nav_menu不兼容。出现的是带有错ID的空帖(并且post_class也不能正常工作):

<div class="post--42 post type-post status-publish format-standard hentry" id="post--42">
        <h2></h2>

代码是:

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <h2><?php the_title(); ?></h2>

错误循环正下方。每个帖子或页面都会显示此特定ID。

有什么想法吗?

编辑添加:

现在在functions.php中我有:

add_action('init', 'register_custom_menu');

function register_custom_menu() {
register_nav_menu('header', 'Header Menu');
}

在我的header.php中,我有:

<?php wp_nav_menu(array('menu' => 'Header Menu')); ?>

我在GUI中选择了我创建的菜单。菜单显示完美,但页面上的内容消失了。

2 个答案:

答案 0 :(得分:0)

根据您提供的信息,我认为您需要添加endwhile,如下所示。如果是这种情况,请告诉我:))

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

and ends here:

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

请务必在主题模板的顶部添加标题模板的调用。如果您在自己的设计中使用The Loop(并且您自己的设计不是模板),请将WP_USE_THEMES设置为false。

<?php define('WP_USE_THEMES', false); get_header(); ?>

参与链接 - http://codex.wordpress.org/The_Loop

答案 1 :(得分:0)

问题在于Shopp插件。显然这是Shopp的一个已知问题:https://shopp.lighthouseapp.com/projects/47561/tickets/1905-shopp-products-in-theme-menu-causes-blank-pages

解决方法是创建自定义菜单项,而不是将产品放入菜单中。