admin管理员组

文章数量:1129424

After upgrading to 3.5, I discovered that navigation has disappeared outside of the main index page. Theme is TwentyEleven and I've verified that this still occurs after disabling all plugins.

<?php if ( $wp_query->have_posts() ) : ?>

    <?php twentyeleven_content_nav( 'nav-above' ); ?>

    <?php /* Start the Loop */ ?>

            <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

            <?php get_template_part( 'content-beers', get_post_format() ); ?>

    <?php endwhile; ?>

    <?php wp_reset_query(); ?>

    <?php twentyeleven_content_nav( 'nav-below' ); ?>

Live site page

After upgrading to 3.5, I discovered that navigation has disappeared outside of the main index page. Theme is TwentyEleven and I've verified that this still occurs after disabling all plugins.

<?php if ( $wp_query->have_posts() ) : ?>

    <?php twentyeleven_content_nav( 'nav-above' ); ?>

    <?php /* Start the Loop */ ?>

            <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

            <?php get_template_part( 'content-beers', get_post_format() ); ?>

    <?php endwhile; ?>

    <?php wp_reset_query(); ?>

    <?php twentyeleven_content_nav( 'nav-below' ); ?>

Live site page

Share Improve this question edited Feb 23, 2015 at 4:15 Pieter Goosen 55.4k23 gold badges115 silver badges209 bronze badges asked Dec 17, 2012 at 19:46 AdamAdam 4771 gold badge8 silver badges19 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

This code didn't change since Twenty Eleven's initial release. Navigation is only printed if your query has more than one page. Could that be it?

Since you are calling $wp_query->have_posts() rather than have_posts(), this suggests you are modifying or overriding the query, which may be confusing WordPress (and it's not WP's fault). (See When should you use WP_Query vs query_posts() vs get_posts()?.)

Winning code (had someone help & it looks like they more or less copy-pasted from the front page. Not sure why I had arranged it differently on the beers page to begin with...

<?php query_posts('post_type=beer&paged='.get_query_var('paged') ); ?>

    <?php if ( have_posts() ) : ?>

        <?php /* Start the Loop */ ?>

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

            <?php if ( 'beer' == get_post_type() ) {

                get_template_part( 'content-beers', get_post_format() ); 

            } else;

        ?>

        <?php endwhile; ?>

        <?php twentyeleven_content_nav( 'nav-below' ); ?>

    <?php else : ?>

本文标签: wp querytwentyelevencontentnav hook no longer outputs navigation link after 35 upgrade