Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Twenty Eleven Theme...

On the home page, I have successfully filtered the loop to display just "Featured" posts with pagination functioning properly through nav links. I'm trying to display posts from all categories on another page called "Unfiltered." Why do the nav links disappear when used on this other page?

edit: if I change the value of 'paged' to '1' or '2', I get the 10 posts that I would expect to so 'paged' seems to work depending on the value I set, just not when I set it to get_query_var( 'paged' )

            <?php /* $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;*/

            $unfiltered_query = new WP_Query ( 

            array (
                'posts_per_page' => 10,
                'paged' =>  get_query_var( 'paged' )
            ) 

        );?>

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

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

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

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

                <?php get_template_part( 'excerpt', get_post_format() ); ?>

            <?php endwhile; ?>

            <?php twentyeleven_content_nav( 'nav-below' ); ?>
share|improve this question
    
Please move your working code to separate answer, usually that is more in line with site's mechanics than editing it in. –  Rarst Aug 26 '11 at 21:56
    
But then it would be buried with unaccepted answers? Hmmm –  Adam Aug 27 '11 at 0:19
    
There is no rule that only one answer is useful and upvoted. :) You can comment on accepted answer and note that you had added solution to which it led as separate one. –  Rarst Aug 27 '11 at 9:35

3 Answers 3

up vote 5 down vote accepted

twentyeleven_content_nav() uses the main query object, $wp_query. You'll need to use the $wp_query variable, rather than $unfiltered_query, then wp_reset_query() to restore the original $wp_query (which it'll find in $wp_the_query, something you should probably avoid touching directly).

As long as you're careful to restore the original query, you're in good shape.

I would submit a patch to core that allows twentyeleven_content_nav() to optionally take a query object which it can use for its calculations.

share|improve this answer

the argument for WP_Query is paged, but the query var is page, no 'd' on the end.

'paged' =>  get_query_var( 'paged' )

should be:

'paged' =>  get_query_var( 'page' )
share|improve this answer
    
Tried that, too. Content navigation still missing. Even tried adding wp_reset_query(); And in case there is any question, I'm using $home_query on the home page. –  Adam Aug 24 '11 at 22:46
    
I am trying to search the difference between the paged and page parameter. Can you please provide me some link to resources? –  Rohit Pande Jan 25 '13 at 9:53
    
@RohitPande - see WP_Query pagination parameters. I think both actually work in most circumstances. –  Milo Jan 25 '13 at 15:46
    
it worked like charm. thanks... –  Harpreet K. Jul 11 '13 at 9:34

What if you replace get_query_var( 'paged' ) with the global $paged? e.g. replace this:

$unfiltered_query = new WP_Query ( 

    array (
        'posts_per_page' => 10,
        'paged' =>  get_query_var( 'paged' )
) 

...with this:

global $paged;

$unfiltered_query = new WP_Query ( 

    array (
        'posts_per_page' => 10,
        'paged' =>  $paged
) 

EDIT

Okay, that apparently won't work. The $paged global apparently isn't set until the query is run.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.