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.

I want to be able to switch back and forth by clicking an anchor tag preferably, between showing a subset of posts and showing all posts, the code I am using is:

query_posts($query_string . '&posts_per_page=-1');

or

query_posts( array(
'posts_per_page' => 45,
//'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),
));

(paged isn't working)

Any way to do this? The problem is I need the 45 limit to show by default, and then a show all anchor tag or button that the user can click.

Any help would be much appreciated!

Thanks! Donna

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You could add a url parameter for posts per page. Something like this:

$pppage = ( get_query_var( 'posts_per_page' ) == 'all' ) ? -1 : 45;
query_posts( array(
    'posts_per_page' => $pppage
) );

then you can set your URL with the parameter posts_per_page=all if you want to show all the posts, if it doesn't find that parameter it will default to 45 posts. You can rewrite this parameter to something like /all/ to show all.

share|improve this answer
    
Thanks! Would I put that in the functions.php file? –  Donna Mar 20 '12 at 13:58
    
You use it wherever your current query is. You'll probably want to do the rewrite in functions.php though. –  m0r7if3r Mar 20 '12 at 14:10
    
OK i'll try it, thanks so much! –  Donna Mar 20 '12 at 14:54
add comment

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.