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.

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!

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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();
        }   
    }
}
share|improve this answer
    
Hi Bainternet, can you please tell me, into which file I should add this hook? Thanks! –  spacemonkey Jun 1 '11 at 12:05
    
in your theme's functions.php would be fine –  Bainternet Jun 1 '11 at 12:06
add comment

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.