Search code examples
phpwordpresslimitposts

Wordpress: Unlimitet Posts on specific Page


for general, the limit of posts per page in my wordpress blog is set to 3 Post.

But on one specific Page i need to show unlimited Posts. Anyone knows how to do this.. i don't get it.

The code on this specific Page (projects) right now

<div id="content" class="fullProjects clearfix full grid">                                  
                <?php while (have_posts()) : the_post(); ?>                                         
                    <?php the_content(); ?>                                                     
                <?php endwhile; ?>  

The 3 Post limit is set in the wordpress admin - backend - not by code.

Thank you for your help!


Solution

  • You can over-ride the settings from the admin page programmatically. You're going to need to tweak your query, though, and over-ride the loop. I think something like this will work:

    global $wp_query;
    
    $args = array_merge( $wp_query->query_vars, array( 'posts_per_page' => '-1' ) );
    query_posts( $args );
    
    while ( have_posts() ) : the_post();
        the_content();
    endwhile;
    

    (I'm putting this together from a couple of different man pages, so it might not be perfect; but it should point you in the right direction)

    Effectively, you're making a new query for posts (the query_posts call). You're passing it a new set of parameters, created from the existing ones via the array_merge; and you're explicitly setting posts_per_page to -1, which should turn off the limit for the number of posts.