Hi
Kindly change this part
$args = array('post_type' => 'news',
'post_status' => 'publish',
'order' => 'desc',
'posts_per_page' => '10'
);
$loop = new WP_Query($args);
to
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'news',
'post_status' => 'publish',
'order' => 'desc',
'posts_per_page' => '10',
'paged'=>$paged
);
$loop = new WP_Query($args);
Regards,
PD
Thread Starter
Chris
(@nutlog13)
Hi PD, thank you for the reply! Unfortunately that code is still not working for me for some reason.
Does it matter that this is on a PAGE template (i.e. not index), or am I missing anything else? I’ve tried changing ‘paged’ to ‘page’ in your code but still no luck…
It seems so simple but the pagination just won’t show up. Thanks!
what plugin or code is used for wp_simple_pagination();
?
does that pagination code work on custom post types?
would the pagination link show if you try to use the generic WordPress functions next_posts_link()
and previous_posts_link()
?
example:
next_posts_link( 'Older Entries', $loop->max_num_pages );
previous_posts_link( 'Newer Entries', $loop->max_num_pages );
http://codex.wordpress.org/Function_Reference/next_posts_link
Thread Starter
Chris
(@nutlog13)
Thanks for the reply. The standard WP functions you posted give me an “Older Entries” link, which goes to the page /latest-news/page/2. However, that page 2 displays the same first 10 posts and won’t actually show any previous posts or pages.
The plugin I’m using is Simple Pagination (https://wordpress.org/plugins/simple-pagination). That gives me a “Pages” title at the bottom of the page, as in the function appears to be working, but no actual links to previous posts/pages. But I can’t figure out why the default WP functions won’t work either. :/
The standard WP functions you posted give me an “Older Entries” link, which goes to the page /latest-news/page/2. However, that page 2 displays the same first 10 posts and won’t actually show any previous posts or pages.
you need to try to apply the fix suggested by @the Grey Parrots, i.e. integrate the ‘paged’ parameter into the query.
your chosen plugin seems to work only with the default query, not with custom queries.
alternatively, have a look at http://wordpress.org/plugins/wp-pagenavi/ which is prepared for custom queries; see http://wordpress.org/plugins/wp-pagenavi/faq/ ‘Does PageNavi work with secondary WP_Query instances?‘ – applied to your case: wp_pagenavi( array( 'query' => $loop ) );
Thread Starter
Chris
(@nutlog13)
Ah, my bad. I had Grey Parrot’s query in there, but I had been trying different things and had changed ‘paged’ to ‘page’ (which some people on The Interwebs had said worked when using it on a page… but not for me).
Anyway, changed ‘page’ in the query back to the original ‘paged’ and NOW your default WP prev/next pagination works fine. I’ll check out PageNavi as well; sounds like that will take care of it.
Thank you very much for the help!
Thread Starter
Chris
(@nutlog13)
Yup, the WP-PageNavi plugin with the ‘paged’ query did the trick. Thanks guys! 🙂