VideoHive

Next/Previous Posts Links don't work [WordPress]

4091 posts
  • Envato Staff
  • Reviewer
  • Community Moderator
  • Venezuela
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Microlancer Beta Tester
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
+9 more
Ivor moderator says

Hi guys,

I’m having a tiny issue with WordPress that I can’t figure out… I just have 7 posts in the Blog Template page and I’m using this code – http://pastie.org/860191

I use query_post to show only the latest 4 posts from the category 6 but when I click the Next Posts link it shows the same 4 posts (not the rest of the posts) and the weird thing is that it shows this path blog/page/2 but I can’t see the others posts.

Here’s the page code http://pastie.org/860191 , there’s any errors in it? Am I missing something? :(

688 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 5 000 and 10 000 dollars
  • Uruguay
_rg_ says

when you use query_posts, you need to hold the original query on a variable, then use a temp variable to hold the new query, and at the end, restore the original query…. or, use a reset query at the end: wp_reset_query();

Just like this:

<?php //The Query

query_posts('posts_per_page=5');

//The Loop

if ( have_posts() ) : while ( have_posts() ) : the_post();

 ..

endwhile; else:

 ..

endif;

//Reset Query

wp_reset_query();

?>

Maybe is that.

Here:

http://codex.wordpress.org/Template_Tags/query_posts

2358 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
digitalimpact says

Shouldn’t the ‘navigation’ div with next/previous posts link be before endwhile?

67 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • France
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
Headset says

You need to declare that the template is paged. See http://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/ ;) this uses WP_query though but it can give you the overall idea.

688 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 5 000 and 10 000 dollars
  • Uruguay
_rg_ says

also you should take this into consideration:

http://theodin.co.uk/blog/design/wordpress-pagination-wppagenavi-queryposts.html

happend to me once.

4091 posts
  • Envato Staff
  • Reviewer
  • Community Moderator
  • Venezuela
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Microlancer Beta Tester
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
+9 more
Ivor moderator says

Thanks a lot guys, I’ll give it a shot. :)

4091 posts
  • Envato Staff
  • Reviewer
  • Community Moderator
  • Venezuela
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Microlancer Beta Tester
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
+9 more
Ivor moderator says

digitalimpact, arriba, headset thanks a lot guys this tutorial works like a charm :) you guys rock! thanks.

@Headset I’ll use WP_Query now :D

67 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • France
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
Headset says
digitalimpact, arriba, headset thanks a lot guys this tutorial works like a charm :) you guys rock! thanks. @Headset I’ll use WP_Query now :D

Glad to help mate :D – keep up the great work!

by
by
by
by
by