WordPress.org

Support

Support » Plugins and Hacks » Hacks » Inheriting parent category template and custom fields

Inheriting parent category template and custom fields

  • I have gathered a function from Full Thought that allows me to inherit the template of parent categories.

    The code:

    function inherit_cat_template() {
      if (is_category()) {
      $catid = get_query_var('cat');
      $cat = get_category($catid);
      $parent = $cat->category_parent;
    	while ($parent){
    	$cat = get_category($parent);
    	  if ( file_exists(TEMPLATEPATH . '/category-' . $cat->slug . '.php') ) {
    	  include (TEMPLATEPATH . '/category-' . $cat->slug . '.php');
    	  exit;
    	  }
    	$parent = $cat->category_parent;
    	}
      }
    }
    add_action('template_redirect', 'inherit_cat_template');

    Now the problem I seem to having is getting custom fields on child categories. It just doesnt want to work.
    How can I resolve this?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Inheriting parent category template and custom fields’ is closed to new replies.
Skip to toolbar