Reputation: 848
I have a code in a page template that looks like this (obviously first I set up IDs of categories):
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
global $post;
$myposts = get_posts("cat=$catIDs&posts_per_page=12&paged=" . $paged);
?>
<div class="column-odd">
<?php
$i=1;
foreach($myposts as $post) :
if($i%2 != 0) :
setup_postdata($post);
//output odd post
endif;
$i++;
endforeach;
?>
</div>
<div class="column-even">
<?php
$i=1;
foreach($myposts as $post) :
if($i%2 == 0) :
setup_postdata($post);
//output even post
endif;
$i++;
endforeach;
?>
</div>
<nav>
<ul>
<?php
if($link = get_previous_posts_link("« Poprzednia strona"))
echo '<li class="prev">'.$link.'</li>';
if($link = get_next_posts_link("Następna strona »"))
echo '<li class="next">'.$link.'</li>';
?>
</ul>
</nav>
The problem is that get_next_posts_link
is not returning anything. How can I make it work?
Upvotes: 0
Views: 3992
Reputation: 11
You simply need to add the following line:
<?php query_posts('post_type=post&paged='. get_query_var('paged')); ?>
just before your get_posts() loop starts.
Full article here: http://blog.onireon.it/wordpress-get_posts-and-pagination-posts-are-correctly-displayed-but-no-pagination-links-are-showing/
Upvotes: 0
Reputation: 735
It won't work with get_posts. You need to use query_posts. I think it should work with the same arguments. edit: you'll also need to save it as $myposts = query_posts( ... ), since you're using two foreach loops like this.
Upvotes: 4