Hi there,
I currently have a WP installation with 4 main categories. For reasons I won't go into, I only want to display posts from a specific category on the blog / main index template. I can accomplish that no problem, but am having problems creating the next/previous post links at the bottom.
Here are a couple of flawed solutions explaining what I'm trying to do, and the reasons why they fail:
Method 1:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post();
// If the post is in category 4...
// <snip> - display the post, etc.
?>
<!--navigation-->
<?php next_posts_link('« Previous Entries') ?>
<?php previous_posts_link('Next Entries »') ?>
This will work for the most part, but if I'm on the last post under category 4, it will still display a 'previous entries' link if there's a post before it in another category.
Method 2:
<?php if (have_posts()) : ?>
<?php query_posts('cat=4');
// <snip> - display the post, etc.
?>
<!--navigation-->
<?php next_posts_link('« Previous Entries') ?>
<?php previous_posts_link('Next Entries »') ?>
This looks like it'll work on first glance, but because of the call to query_posts('cat=4'); it will always display the first 2 posts under that category (blog set to show only 2 posts per page). I could add parameters to it e.g. `showposts=2&offset=1, but I can't add params like that to next_post_link or previous_post_link.
What is the smartest way to accomplish displaying only posts from a certain category, and having accurate navigation to navigate between the next/previous entries at the bottom?