Load specific `Base` template (base-*.php) based on `Main` template (category.php)

I’m trying to load a specific Base template (let’s name it base-template-bi.php based on specific Main template (let’s name it category.php).

So the goal is to call this <?php get_template_part('templates/page', 'category-header'); ?> only on category template (category.php).

Visually, it looks like this:




Another workaround I could think of; I was thinking of (and actively googling my way through this) to use a if else statement inside my Base template base-template-bi.php to only trigger on a category page. Something like this perhaps (sorry for my noob trial not much of a programmer/coder);

<?php
    // 
    if (current_main_template('category.php')) {
      get_template_part('templates/page', 'category-header');
    } else {
     //blank
    }
  ?>

What are the options I’m looking at to achieve this?

Have you had a look at the docs? Specifically the Intro to the Roots Theme Wrapper. The whole document is worth a read, but step 2 and 3 seem related to your issue.

In short, I believe you are looking for base-category.php instead of base-template-bi.php

Edit:
If the only thing you want to edit is the title, then I suggest just updating the roots_title() function by adding a conditional is_category() and return single_cat_title( '', false ) to display the category name.

But, the roots_title() function already takes care of taxonomy names so it is worth looking into why that is not working

References:
https://github.com/roots/roots/blob/master/lib/titles.php
http://codex.wordpress.org/Function_Reference/is_category
http://codex.wordpress.org/Function_Reference/single_cat_title

1 Like

@enollo,

Thanks for the pointers and help. Appreciate it.

I never realized about lib/titles.php so that’s very useful. I ended up using this though as it’s the working solution I was looking for (I’m not sure how good the code is though):

    <?php        
       if (is_home() || is_404()) {
       } else {
         get_template_part('templates/page', 'category-header');
       } 
     ?>

<img src="https://www.evernote.com/shard/s89/sh/2df88663-d56e-4bf3-bbb2-bec8df618618/23308c0e3acec69eb9ccc92730193588/deep/0/Business-Insider---Just-another-WordPress-site.png />