I need paging on news archives page. Data is coming correctly if display all records on same page. But if i add paging code, then pagination values (such as 1,2,3,...16) coming correctly, but if i click on page 2 then it displays the same post title as on page 1.
<h1 style="margin-left:10px;">News</h1>
<ul class="years">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$all_posts = get_posts(array(
'post_type' => 'news',
'posts_per_page' => 20,
'orderby' => 'date',
'order' => 'DESC',
'paged='. $paged,
));
// this variable will contain all the posts in a associative array
// with three levels, for every year, month and posts.
$ordered_posts = array();
foreach ($all_posts as $single) {
$year = mysql2date('Y', $single->post_date);
$month = mysql2date('F', $single->post_date);
// specifies the position of the current post
$ordered_posts[$year][$month][] = $single;
}
// iterates the years
foreach ($ordered_posts as $year => $months) { ?>
<li>
<h3><?php echo $year ?></h3>
<ul class="months">
<?php foreach ($months as $month => $posts ) { // iterates the moths ?>
<li>
<h3><?php printf("%s (%d)", $month, count($months[$month])) ?></h3>
<ul class="posts">
<?php foreach ($posts as $single ) { // iterates the posts ?>
<li>
<?php echo mysql2date('F j', $single->post_date) ?> <a href="<?php echo get_permalink($single->ID); ?>"><?php echo get_the_title($single->ID); ?></a> (<?php echo $single->comment_count ?>)</li>
</li>
<?php } // ends foreach $posts ?>
</ul> <!-- ul.posts -->
</li>
<?php } // ends foreach for $months ?>
</ul> <!-- ul.months -->
<?php if(function_exists('wp_paginate')) {
wp_paginate();
} ?>
</li> <?php
} // ends foreach for $ordered_posts
?>
</ul><!-- ul.years -->
here is the screen shot:-
