Blogger Template by Blogcrowds

A nagging dilemma is how to to get child categories in Wordpress to selectively inherit their parent's theme, which is in category-x.php.

This is probably not the most elegant solution, but going off on what someone said in a WP forum , and some code from Lorelle, here's what I came up with. Since I only have four categories to check, I'm not too concerned about the server load.

Put this in the category.php page, which will now serve as a template switcher.

< ?php $this_category = get_category($cat); ?>
< !-- If category is parent, list it -->
< ?php if ($this_category->category_parent == 0) { ?>

< ?php $this_category->category_parent = $cat; ?>
< ?php } else { ?>
< !-- If category is not parent, list parent category -->
< ?php $parent_category = get_category($this_category->category_parent); ?>

< ?php
$pid=$parent_category->cat_ID;
if ($pid=='7')
    include (TEMPLATEPATH . '/category-7.php');
elseif ($pid=='6')
include (TEMPLATEPATH . '/category-6.php');

else

?>


< ?php } ?>
UPDATE: There's also a good plugin that seems to do similar things: WP Extra Template Tags 0.3

Description

Template tags is a really good thing i Wordpress. Unfortunately there are some tags missing. I created a plugin to provide Wordpress users with extra template tags. It can be used in themes or plugins.

Newer Posts Older Posts Home