I am using WP3.5, and I have a post_list.php
which will show all the posts order by post date DESC. Everything is ok except pagination
.
I have 15 posts, for test purpose, I want to every page show 2 posts, others will be show next page like this.
Prev 1 2 3 4 5 Next
Some parts of post_list.php
define('WP_USE_THEMES', false);
require_once '../blog/wp-load.php';
$query_args = array(
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 2,
'offset' => 0
);
$lateset_posts = get_posts($query_args);
<?php
global $post;
foreach($lateset_posts as $post) :
// do something
the_content();
<?php endforeach;?>
<?php next_post_link(); previous_post_link(); ?>
Yes, as you see, every page show 2 posts as I set, but I cannot get the pagination as I want to. Instead, it shows me like this
Post1's title >> << Post2's title
How could I get the pagination style like below
Prev 1 2 3 4 5 Next
Thanks.
Edit:
Now I use paginate_links
function, yes, I got what I want.
$query_args = array(
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 2,
'offset' => 0
);
$lateset_posts = get_posts($query_args);
$paging_args = array(
'base' => '%_%',
'format' => '?paged=%#%',
'total' => count($lateset_posts),
'current' => max(1, get_query_var('paged')),
'end_size' => 1,
'mid_size' => 1,
'prev_next' => True,
'prev_text' => __('« Previous'),
'next_text' => __('Next »')
);
$lateset_posts_paging = paginate_links($paging_args);
I have 15 rows , and it shows like this
1 2 3 .. Next
Now I am in the first page, and I want to go to the second page, so I click the number 2, and I notic the url is :
http://localhost/x/post_list.php?paged=2
But after I click it ,it still in the first page
, and the data is also the first two rows. Where is am I wrong , Thanks.