1

Been trying to use the pagination functions in wordpress with this code

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array( 'post_status' => 'pending', 'posts_per_page' => 3, 'paged'=>$paged);
$recent_posts = new WP_Query( $args );
?>

<?php while ( $recent_posts->have_posts()) {
$recent_posts->the_post();
echo '<div id="votes"><li id="voteimage"><a href="' . get_permalink() . '" title="' . esc_attr( $recent["post_title"] ) . '">';
echo get_the_post_thumbnail($recent["ID"], 'thumbnail');
echo '</li></a>';
echo '<li class="vote-title"><a href="' . get_permalink() . '" title="Look '.esc_attr($recent["post_title"]).'" >' . get_the_title() .'</a> </li>';
echo '<li class="vote-desc"><a href="' . get_permalink() . '">' . get_the_excerpt(10) . '</a> </li>';
echo '<ul class="vote-footer"><li>Author: <a href="http://streakingpirates.com/forum/users/' . get_the_author() . '">' . get_the_author() . '</a></li></ul>';
echo '</div>'; 
} 
?>
<?php posts_nav_link(); ?>
<?php next_posts_link('« Previous Entries') ?>
<?php previous_posts_link('Next Entries »') ?>

And yet each time I try I just can't seem to get it right, any help would be appreciated cheers.

Result page here: http://streakingpirates.com/pending/ excuse the random posts by my friend

Solution found thanks to cale_b and the link he provided https://wordpress.stackexchange.com/a/120408/11704

needed to swap

<?php next_posts_link('« Previous Entries') ?>

for

<?php next_posts_link( 'Older Posts' , $custom_query->max_num_pages ); ?>

since apparently the previous pages link has some issues with custom loops

  • Where is the pagination function you are trying to use? Or, are you meaning that it's not listing the right number of posts? (It is). What do you mean, can't seem to get it right? – cale_b May 20 '14 at 23:47
  • I'll add things such as "posts_nav_link();" and it doesnt show, think I need to use the $recent_posts in there somewhere, not sure – PirateScott May 20 '14 at 23:53
  • Got it. OK, the issue is that it's a custom loop - in order to do pagination on a custom loop, there's a lot of special things you need to do. See this answer (very thorough) which should get you where you need to be: wordpress.stackexchange.com/a/120408/11704 – cale_b May 21 '14 at 0:06
  • That's a long read! Cheers I'll take a look. – PirateScott May 21 '14 at 0:10
0

Well, I see three posts! :-)

Just an idea, but maybe you only need to add the next/prev links? http://codex.wordpress.org/Function_Reference/posts_nav_link

Edit:

This (http://streakingpirates.com/pending/page/2) works for me, so I guess it must be the links you're after!

  • That's mostly my problem, I do that and nothing appears, not sure if I'm placing it correctly or I'm missing a $recent_posts to fix it. I've put it in the edit to show you the new code but it's appearance on the website doesnt change at all – PirateScott May 20 '14 at 23:47
  • I don't see any posts_nav_link() or previous_posts_link() in your code. Are you calling those functions at all? – Pim May 20 '14 at 23:50
  • Just added it to show you, sorry took a while to edit. – PirateScott May 20 '14 at 23:52
  • Where's your "endwhile" ? :-) Your call needs to be outside the loop I believe. - Oh sorry totally misread that... let me give it a look – Pim May 21 '14 at 0:01
  • 1
    Found the issue but cheers! I'll post the solution – PirateScott May 21 '14 at 0:18
0

needed to swap

<?php next_posts_link('« Previous Entries') ?>

for

<?php next_posts_link( '« Previous Entries' , $custom_query->max_num_pages ); ?>

since apparently the previous pages link has some issues with custom loops

Solution found thanks to cale_b and the link he provided https://wordpress.stackexchange.com/a/120408/11704

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.