• Hi,

    I have 2 loops in my index page

    <?php
    $posts = get_posts('category=1&numberposts=1');
    foreach($posts as $post) :
    setup_postdata($post);
    ?>

    and


    <?php query_posts('cat=-3'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    This seems to be messing up my previous/next links. I get the same posts on all the pages.

    How do I resolve this?

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • See if there is anything here that might be helpful:
    https://www.ads-software.com/support/topic/38210

    Thread Starter chugs

    (@chugs)

    Thanks for the reply moshu. I tried that and it doesn’t work.
    Any other suggestions?

    I have the same problem, nobody knows the solution?

    On that other link I gave above there are a few different solutions. Which one did you try and didn’t work for you?

    Hi moshu,
    I have a template where I need to have the first post different than others, so there I use in header.php something like this:

    <?php if(have_posts()): ?>
    			<?php query_posts('showposts=1'); ?>
    			<?php while(have_posts()): the_post(); ?>
                              ....
    		    <?php endwhile; ?>
        	<?php endif; ?>

    and then I have another loop which is in index.php:

    <?php
    			if (is_home()) {
    				$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    				query_posts("offset=1&paged=$paged");
    				echo $paged;
    			}
    			?>
    ...the loop...

    When I go to another page the value of the $page is always 1 – so that’s why it not works ??

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    If you are using query_posts, then you need to include the query_string. Like this:

    query_posts($query_string . "&cat=3,5");

    Without the query_string, pagination and a few other things won’t work properly.

    I still can’t get it to work. Is there any connection with offset parameter and paged parameter? I’m setting offset=1 because the first post is displayed in another loop.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    depi: Your loop is wrong. query_posts should come outside it, and also use the query_string. Like so:

    <?php query_posts($query_string.'&showposts=1'); ?>
    <?php if(have_posts()): ?>
    <?php while(have_posts()): the_post(); ?>
          ....
    <?php endwhile; ?>
    <?php endif; ?>

    Your second loop has a similar issue with the query_string:

    if (is_home()) {
    query_posts($query_string."&offset=1");
    }

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘2 loops and pagination doesn’t work’ is closed to new replies.