WordPress.org

Ready to get started?Download WordPress

Forums

multiple custom loops and pagination (3 posts)

  1. sonogun
    Member
    Posted 2 years ago #

    I have to create a custom WordPress category.php page. I need a custom loop at the top pulling in the latest two posts in the category (these are styled differently). I then need a second custom loop pulling a second list of 10 latest posts in that category. the pagination then needs to work correctly.

    I have gone through so many posts regarding the pagination issue with query_posts() but can't seem to get anywhere, please help!!

    here is what I am currently using:

    <?php query_posts('posts_per_page=2'); if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    <!--first loop stuff-->
    <?php endwhile; endif; ?>
    <?php query_posts('offset=2'); if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    <!--second loop stuff-->
    <?php endwhile; ?>
    	<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
    	<?php else : ?>
    		<h2>Not Found</h2>
    	<?php endif; ?>
  2. eddioot
    Member
    Posted 2 years ago #

    Maybe you can try the following:

    $temp = $wp_query;
      $wp_query= null;
      $wp_query = new WP_Query('offset=2&paged=' . $paged);

    And then for the query:

    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

  3. sonogun
    Member
    Posted 2 years ago #

    Hi Thanks for your suggestion, I used this for the query and it worked but I finally figured out that it was actually the fact that I was using "offset" in the query that was messing up the pagination.

    So pagination and wp_query "offset" gives issues. I eventually found a fix for this here:
    http://weblogtoolscollection.com/archives/2008/06/19/how-to-offsets-and-paging/

Topic Closed

This topic has been closed to new replies.

About this Topic