The loop below is one of several on a Custom Page template, but it’s the only loop that I’m trying to implement Pagination with.
Once I have Pagination working for this one loop, I’ll be implementing InfiniteScroll which I’m sure will be way easier than installing it first…
I’ve read miles of pages but my brain just isn’t finding the right information to get this to work yet.
Designing themes is one thing, but engineering loops is still something I struggle with.
<div class="thirdLeft">
<?php
global $paged;
$curpage = $paged ? $paged : 1;
$args = array(
'post_type' => 'location',
'orderby' => 'post_date',
'posts_per_page' => 5,
'paged' => $paged
);
$first_query = new WP_Query('cat=2,-20&showposts=18&offset=2');
while($first_query->have_posts()) : $first_query->the_post();
?>
<?php get_template_part( 'content', 'single' ); ?>
<?php endwhile; ?>
</div>
UPDATE
After scouring the web, I found this great tut:
http://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/
Formatting my loop above to work and get the pagination it deserves, an updated version looks like this:
(not much changed from the tut, aside from custom categories)
<?php add_filter('post_limits', 'my_post_limit'); ?>
<div class="thirdLeft">
<?php
global $myOffset;
$myOffset = 2;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('offset='.$myOffset.'&cat=2,-20'.'&showposts=18'.'&paged='.$paged);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
</div>
<div class="longLoopNav">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
<?php $wp_query = null; $wp_query = $temp;?>
<?php remove_filter('post_limits', 'my_post_limit'); ?>
Now to figure out Infinite Scroll to load more posts into this loop with Ajax
Why can’t you write custom pagination?
Using:
<?php theme_get_next_posts_link($first_query); ?>
for Older Posts<?php theme_get_previous_posts_link(); ?>
for Newer PostsIn your code: