Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a few categories.

in each of them, I have only one post.

by clicking on a category, I have to click on that single post to enter.

I wish, by clicking on the category, enter directly in that one post.

This method avoids having to click two times in the post.

Any suggestions for what I have to use code in archive.php?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

this function will check if you're on a category page and 302 redirect to the latest post in that category. put it in your theme's functions.php file.

function my_check_if_cat(){
    if ( is_category() ) :
        $category = get_the_category();
        $latest = query_posts('showposts=1&cat='.$category[0]->cat_ID);
        if(have_posts()) :
            wp_redirect(get_permalink($post->ID), 302);
        endif;
    endif;
}
add_action('template_redirect','my_check_if_cat');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.