I have a page template that is querying a news category of blog posts. I've set my Reading Settings to show up to 4 posts at a time (Blog pages show at most).
However the page template is currently displaying over 4 posts. Is there something else I need to tie into this page? I'm really trying to get the next_posts_link to activate, however no such luck yet. Here's my code:
[Code moderated as per the Forum Rules. Please use the pastebin]
mfshearer72
Member
Posted 11 months ago #
Is your posts_per_page=-1 overriding the Reading Settings? To my understanding, the -1 value shows all posts in Category.
See the section: All Posts in a Category on this page:
http://codex.wordpress.org/Function_Reference/query_posts
mfshearer72,
I noticed that shortly after posting this. I removed the code &posts_per_page=-1 - so now the page does only display 4 posts.
However I can't get the following code to show up:
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div id="nav-above" class="navigation">
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>
</div><!-- #nav-above -->
<?php endif; ?>
Should I use something besides wp-query?
mfshearer72
Member
Posted 11 months ago #
You are asking, from a page, to show the next and previous posts of your "news" category.
WordPress doesn't understand this b/c those queries (display the posts by category) and the max_num_pages are independent.
I'm not sure at the moment how to resolve that, but if I think of it, I'll follow up.
I figured out the problem, my code was running outside of the loop. It's been fixed. Thanks for your help!