Base-category.php

Hi guys. im trying to make a custom template for each category that i got.
Im having trouble to getting this work, i added a base-category.php but it didnt replace the main base.php

I use to have this on custom.php to see what are the roots template that the page displayed is using but now isn’t working anymore

add_action('wp_footer', 'roots_wrap_info');

function roots_wrap_info() {  
  $format = '<h6 style="color:#FFF;">The %s template being used is: %s</h6>';
  $main   = Roots_Wrapping::$main_template;

  global $template;
  printf($format, 'Main', $main);
  printf($format, 'Base', $template);
}

Do you have a category.php file too?

I dont have a category.php, if i add a category.php when i display a category the page get’s an infinite loop.
I’m still trying

The base-category.php template will only take precedence over base.php when you are using category.php to display your categories, or when you add a filter (see the custom post type filter towards the end of this article).

The easiest way to do this is to duplicate base.php and index.php and rename them base-category.php and category.php respectively.

2 Likes

Thanks a lot!, now i got it working, i read the cpt filter it will help me a lot.

The filters in roots will allow me to get the same template for a child category?
I got a “videos” category and then inside videos i got “media”, if i create category-videos.php it only works with “videos” category but not the child category “media”, for these i need to make a filter right? o there is another better way?

You’re correct. A filter is the best way to do that.

Of course if there are just minor changes needed in the base templates, then I would probably use conditional statements instead.

1 Like

I would check conditional statements. The only thing that changes in diferents category is the way post are displayed, Videos and child of videos will be displayed as square with info and other will be as a list with thumb.

Thanks Foxall

Ok i wrote this code

I put this on a new category.php

$cat = get_the_category();

$catParent = $cat[0]->category_parent;
if($catParent == 0){
$catName = $cat[0]->name;
}
else{
$catName = get_cat_name ($catParent);
}

echo $catName;

Now that i got $catName i cant use it to get the post format depending on the parent Category.