WordPress.org

Ready to get started?Download WordPress

Forums

Inheriting parent category template and custom fields (2 posts)

  1. TheChosen1
    Member
    Posted 1 year ago #

    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?

  2. mentorcs
    Member
    Posted 1 year ago #

    Hi, Were you able to solve your problem?

Topic Closed

This topic has been closed to new replies.

About this Topic