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');


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


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.

  • 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. – mor7ifer Mar 20 '12 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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