I currently grab an array of user data from a query. I then use a foreach to loop through them and apply styles and divs to output them to the page. This all works great but i would like to paginate the array into the wordpress paged option. So if the user has set the max posts per page to be 10 and the array contains 20 results i want to stop at 10 and have a link to view the next page which would show 11-20. I have done something similar in the past with the standard wordpress loop with a if have posts thing with:
<? $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;?>
<?php if ( have_posts() ) : ?>
$limit = get_option('posts_per_page');
$args = array(
'paged' => $paged,
'post_per_page' => $limit
);
query_posts($args);?>
<?php while (have_posts()) : the_post(); $counter++; ?>
Then i would have the prev / next links:
<?php if ($counter == $limit) { ?>
<div class="greyBtn nextBtn"><?php next_posts_link('<span>Next »</span>') ?></div>
<?php } ?>
<?php if ($paged > 1) { ?>
<div class="greyBtn previousBtn"><?php previous_posts_link('<span>« Prev</span>') ?></div>
<?php } ?>
I want to do this same logic for my foreach:
<? foreach ($all_members as $member) {?>
//Do Loop Stuff
<?php } ?>
Any ideas on how to do this?
$paged
set?<?php if ( have_posts() ) : ?>
should be after the query posts call, else you're checking the existing query, then altering it. Aside from that, what specifically isn't working for you? No results on page 2? Something else?