if there is only one post in the category, directly open

I have a few categories.

in each of them, I have only one post.

Read More

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?

Related posts

Leave a Reply

1 comment

  1. 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');