Display most recent post in category instead of archive?

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);          

2 Answers
2

You know, the other way to do what you’re trying to do is simply to set the global posts_per_page variable to 1 in Dashboard -> Settings -> Reading.

Leave a Comment