WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Previous & Next don't work, page 2 is same as page 1, 2 custom loops on Index (2 posts)

  1. alessia_e
    Member
    Posted 3 years ago #

    Hello,

    I am having a similar issue to some other people: I have two loops on my Index page, and when I use PREVIOUS & NEXT buttons, the 2nd page displays posts of first page. I've tried adding various code snippets mentioned here on the forums, but there is no progress. Please take a look & let me know where I am going wrong with the code... Thank you very much!

    Site: shalasrabbithole.com/blog

    Loop 1 beginning (large main post):

    <?php
    				$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // pagination
    					query_posts( 'cat=-9,-10&showposts=1&posts_per_page=11&paged=' .$paged );
    					if (have_posts()) :
    						while (have_posts()) : the_post(); $category = get_the_category();
    				?>

    Loop 2 beginning (horizontal double posts):

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // pagination
    					query_posts( 'cat=-9,-10&showposts=10&offset=1&posts_per_page=11&paged=' .$paged);
    					if (have_posts()) : $counter = 0;
    						while (have_posts()) : the_post(); $category = get_the_category();
    
    						if( $counter % 2 == 0 )
    							$end = "";
    						else
    							$end = "last";
    				?>

    And this is the PREVIOUS | NEXT code:

    <div class="left">
    <?php
    previous_posts_link( __( '<img src="http://www.shalasrabbithole.com/blog/images/old_leaf.jpg" width="132" height="26" align="left" border="0"/>' ) ); ?>
    
    <?php
    next_posts_link( __( '<img src="http://www.shalasrabbithole.com/blog/images/new_leaf.jpg" width="133" height="26" align="right" border="0"/>' ) ); ?>

    Thank you for your time!!!

  2. alessia_e
    Member
    Posted 3 years ago #

    New code (I modified it by trial and error!)

    Loop1:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // pagination
    				query_posts( 'cat=-9,-10&showposts=1&posts_per_page=11&paged=' .$paged );
    					if (have_posts()) :
    						while (have_posts()) : the_post(); $category = get_the_category();
    				?>

    Loop2:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // pagination
    					query_posts( 'cat=-9,-10&posts_per_page=10&paged=' .$paged);
    					if (have_posts()) : $counter = 0;
    						while (have_posts()) : the_post(); $category = get_the_category();
    
    						if( $counter % 2 == 0 )
    							$end = "";
    						else
    							$end = "last";
    				?>

    Previous/Next:

    <?php
    previous_posts_link( __( '<img src="http://www.shalasrabbithole.com/blog/images/old_leaf.jpg" width="132" height="26" align="left" border="0"/>' ) ); ?>
    
    <?php
    next_posts_link( __( '<img src="http://www.shalasrabbithole.com/blog/images/new_leaf.jpg" width="133" height="26" align="right" border="0"/>' ) ); ?>

    Lesson: Watch out for the offset values - it screwed me up.

Topic Closed

This topic has been closed to new replies.

About this Topic