• Hello,

    I’ve been researching all day and I cannot find anything that answers what I need.

    I have several categories on my site that I need to have different templates. I need to somehow tell it what categories to use for different templates.

    Here is an example of what I have tried to do. Here is my category.php page:

    <?php
      if ( is_category('directory') ) {
      include(TEMPLATEPATH . '/directory.php');
    
      } elseif ( is_category('2') ) {
      include(TEMPLATEPATH . '/archive.php');
    
      } else {
      include(TEMPLATEPATH . '/archive.php');
    
      }
    ?>

    The directory.php file is basically just the archive.php for now until I can figure out the issue. The screen keeps coming up blank.

    Any ideas?

    Thanks

Viewing 10 replies - 1 through 10 (of 10 total)
  • You’re over-complicating your approach. See http://codex.ww.wp.xz.cn/Category_Templates. Especially the section entitled “What Template File is Used? ”

    Thread Starter daenterpri

    (@daenterpri)

    I understand the heirarchy, but what if I want like 30 categories to have a different template because they are part of my sites business directory?

    Also, even if I was only needing to change a single template, its still not working. I put the archive.php code into a file called category-195.php (195 is the category ID) to test and its still coming up blank.

    Any ideas?

    Have you tested archive.php? Try copying index.php instead.

    Thread Starter daenterpri

    (@daenterpri)

    Aha! I got it working! Thanks for your help, I must have had a flaw in the archive.php code I copied over. All of that is working well now.

    Now…do you have any recommendations for me in dealing with large groups of categories that I would like to all have the same template?

    Otherwise, I will have 100’s of category-xx.php files by the time I get done.

    Thanks for your help!

    Andy

    Thread Starter daenterpri

    (@daenterpri)

    I wish there was a way that I could say “every sub category of this category gets this template”…is there a way?

    I had a similar problem when a client of mine wanted different themed-images displayed on category pages. I managed to sub-divide the categories into 4 main groups (in this case “Weddings”, “Baby” and “Parties” with a “Default” groups for anything left over) and run the whole thing from a single catgeory template.

    Since my client had a habit of deleting and creating categories left, right and center, I opted to filter on category name rather than id, and came up with:

    $one = array('bridal','wedding','weddings','bride','attendants','groom','reception','honeymoon');
    $two = array('baby','babies','toddlers','toddler','nursery','feeding','toys','strollers','birth','nursing','kids','bathtime');
    $three = array('bachelorette','holiday','party','parties','birthday','invitations','paper','celebrations');
    
    $this_category = get_category($cat);
    $this_cat_name = explode(' ',strtolower($this_category->cat_name));
    $this_cat_name = str_replace(',','',$this_cat_name);
    
    $mycat = 'default';
    if(array_in_array($one, $this_cat_name)) $mycat = 'one';
    if(array_in_array($two, $this_cat_name)) $mycat = 'two';
    if(array_in_array($three, $this_cat_name)) $mycat = 'three';

    I was then able to grab a random image from the relevant folder (as specified by $mycat).

    Perhaps you could use a similar approach and either output a different div class and apply changes via CSS or use an include TEMPLATEPATH to pull in a completely different template snippet?

    Thread Starter daenterpri

    (@daenterpri)

    Yowsers! Thanks! What file would I start to put something like that in do you think?

    Thread Starter daenterpri

    (@daenterpri)

    Oh, gotcha, single category template. So I should probably start messing with that in category.php.

    Thread Starter daenterpri

    (@daenterpri)

    Hmmmm, if anyone else would like to give me a hand in setting this up it would be much appreciated…I’m not much of a programmer! πŸ™‚

    Thread Starter daenterpri

    (@daenterpri)

    For future, this post helped a ton! The plugin on this post is just what I needed. It allows all of the child categories to use the parent category template. Perfect.

    http://ww.wp.xz.cn/support/topic/58382?replies=6

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Multiple Category Templates’ is closed to new replies.