How to override Category rendering mechanism

Currently for every category there is a separate template (category-1.php, category-2.php, etc..), in my case there is over a hundred of them. I want refactor it to 4, so for instance if $cat is in range 1..20, render “first_category.php”, if in range 21..50, render “second_category.php” and so on.

Thanks!

Related posts

Leave a Reply

1 comment

  1. if you can use template_redirect hook and a simple function to set the template to use

    add_action( 'template_redirect', 'category_set_redirect' );
    function category_set_redirect(){
        //create the sets of categories
        $first_set= array("1","2","3","4","5","6");
        $second_set= array("7","8","9","10","11","12");
    
        if (is_category()){
            if (in_array(get_query_var('cat'),$first_set)){
                include(TEMPLATEPATH . "/first_category.php"); // include the corresponding template
                die();
            }
            if (in_array(get_query_var('cat'),$second_set)){
                include(TEMPLATEPATH . "/second_category.php"); // include the corresponding template
                die();
            }   
        }
    }