I’ve successfully redirected my blog page to my most recent post – i.e. so when you click the ‘blog’ link in the nav it goes to the most recent post page and you can click next/prev buttons to navigate between other posts.
Now I want to do the same thing but for a specific category so when you click a category link, instead of displaying an archive page of all the posts in that category, it displays the most recent post in that category.
The next/prev buttons then need to navigate to posts only in that category.
Any ideas how I can do this?
Thanks
===============UPDATE===============
I copied my code from single.php to category.php and used single_cat_title(); to display the category name at the top of the page.
Needed to change my next/previous_post_link to next/previous_posts_link
The only disadvantage is that the URL displays /cat=[catname]&paged=2 rather than the name of the post, but not really a big problem.
The only issue remaining is how to display the full screen background image which is attached to each post and referenced as follows in my header.php:
$background_image = get_post_meta($page_id, 'mb_background_image', true);
$src = wp_get_attachment_image_src($background_image, 'full');
How can I call this from the category page?
===============UPDATE 2===============
Fixed by replacing this line:
$background_image = get_post_meta($post->ID, 'mb_background_image', true);
You know, the other way to do what you’re trying to do is simply to set the global
posts_per_page
variable to1
in Dashboard -> Settings -> Reading.You can do this by creating a template in your theme called category.php using the following.
You can maintain category consistency by using the following function. Make sure in_same_cat is set to true.
Please see the examples here: http://codex.wordpress.org/Function_Reference/previous_post_link and http://codex.wordpress.org/Function_Reference/next_post_link
Not sure how you want to handle the same category for the posts links. There’s really no context to say which category is the one that should be chosen. If there are common categories between posts, it will use that in the query. You can alter the query using the following. I don’t know exactly what you wish to do so I included a var_dump so you can see what’s going on behind the curtain.