NO BUG: Template system just doesn't work

I’ve asked this question four times with no response at all. So I’m just going to have to keep posting it until it gets an answer. Yes, I’ve searched the forum. No, none of the answers works or meets my question. This asks about themes, but I have the same issue with templates.

I have a CPT (projects) with many categories. For simplicity, let’s say I have categories A, B, C (and e, f, g) - and all of them have sub-cats.

The client wants different styles for 2 of the many categories (and their children). So I create a theme style for each category. A ‘Theme-Global’ (for the whole website, cats c, d, e, f etc.). Theme A only for archives/posts of cat A. Theme B for archives/posts of cat B.

Then conditions to show them. But nothing works properly.

If I set them all to the relevant terms (inc children)/archives - it works for all terms and archives - but all posts take their style from Theme Global.

If I add ‘post type projects’ to the conditions, all posts of every category take on Theme B (even posts not in the categories Theme B is set to apply to).

There appears no way to apply a theme (or template for that matter) to just one term/category and its posts.

Given the lack of answers I’ve wasted many hours on this and am painfully frustrated. I don’t understand how such an excellent tool as Bricks has such an opaque and bewildering template system.

Given my fair certainty no-one will answer anyway, I’m just going to rant… I have set GLOBAL theme to EXCLUDE ABCD, and set OTHER THEME to INCLUDE ABCD - and still the global theme is applied to posts in categories ABCD.

All it needs is a little box in conditions marked ‘Priority’ - so I can set the specific to high (e.g. 10) and the general to low (e.g. 1) and then the right theme/template would apply.

Hi

Maybe not the answer you expected, but…

I would just make one template for the CPT and inside the template make a section for each category.

Then I would add for each section the condition to only show it if the category equals the category from the post.

Cheers

Patric

Thanks Patric, but the theme affects the header and footer too. So conditional elements won’t cut it.

Use only one condition for terms. Then everything works.

Thanks, but this does not work at all.

I can get the styles to apply to a single term, but not to posts in a child of that term. So I will have to educate the client to always tick the main category AND the sub-cat which actually applies.

Be great if one day the TERMS condition had an ‘include child’ also.

And in fact this doesn’t work either. I realise now that the styles apply to all the right places, and some of the wrong ones… and even explicit ‘exclude’ conditions don’t prevent it.

If I have these CPT terms:
PARENTTERM

  • TERM-A
    — this
    — that
    TERM-B
    PARENTTWO
  • TERM-C
    — 1
    — 2
    — 3

I have a THEME STYLE → Conditions = TERM-C
(and/or archives-> categories & tags-> TERM-C - include children – adding this condition doesn’t fix it).

I have a post in term child 2. The THEME STYLE TERM-C does not apply.
If I also check TERM-C for that post, the THEME STYLE applies. So TERM condition does not include children, or have the option to include them.

Fun fact: I have a GLOBAL THEME STYLE. It applies site-wide.
I have a second THEME STYLE for TERM C. It should only apply to terms/posts with the term ‘TERM-C’
If I have a loop on a page in TERM-B, which pulls in a post from ‘2’ - the theme style is applied to that page, even if I explicitly exclude the style from TERM-B

I can make no sense of that at all.

I thought about just hand-coding a stylesheet instead, and targeting the classes. But Bricks doesn’t add classes to the body like most themes. So I thought I would add some. It adds the classes, but breaks the builder. Can someone tell me why and how to prevent the code firing when the bricks builder is running?

function custom_body_classes( $classes ) {
if ( !bricks_is_builder_main() ) {	
if ( is_singular('projects') ) {
		global $post;
		$my_terms = get_the_terms( $post->ID, 'project_type' );
		if ( $my_terms && ! is_wp_error( $my_terms ) ) {
			foreach ( $my_terms as $term ) {
				$classes[] = $term->slug;
			}
		}
		return $classes;
	}
} }
add_filter( 'body_class', 'custom_body_classes' );

Write to support they will help

Hi Mike,
Thanks so much for your report!

Unfortunately, due to the sheer volume, we can’t respond to every post here in the forum and hope for the help of the community, especially in the How To’s.

Regarding your specific problem, it would be very helpful if you could provide us with access data to a test environment that shows the problem in a simplified form. In addition, a screencast explaining where the problem is and what exactly you expect it to do would be desirable. This makes it easier for us to understand what the issue is and whether it is a bug or a comprehension issue.

Please send temporary login credentials, a link to this thread, and a screencast to help@bricksbuilder.io using the email address you used during the purchase, so we have the chance to take a look at it.

Best regards,
timmse

Hi @timmse
I have a reply from support, so to avoid taking your time I will talk to them. Thank you tho, I appreciate the efforts you make here.

For ‘interest’ or the benefit of others who land here. The issue is (probably me!) that you can’t target posts of XXX term.

You can target archives with ‘archive’, terms archives with ‘term’ conditions. But you can’t target a post that has XXX as it’s term or term parent. Something about how you decide where we are in the hierarchy - I think it uses the URL. And WP has the famous shortfall of not allowing easy URLs for CPTs, once you hit the post, the URL becomes just (site)/post_name. So the conditions no longer apply.

I’ve looked at posts which explain how to add the term to the url, but they are too much for my meagre skills.

This meant that I could target fairly well for archives/terms, but at post level it fails. It reverts to ‘the most recently declared’ style, and ignore conditions.

Support offered this code fix:

function custom_body_classes( $classes ) {
    if ( !bricks_is_builder_main() && is_singular('projects') ) {    
        global $post;
        $my_terms = get_the_terms( $post->ID, 'project_type' );
        if ( $my_terms && ! is_wp_error( $my_terms ) ) {
            foreach ( $my_terms as $term ) {
                $classes[] = $term->slug;
            }
        }
        return $classes;
    }
   
    return $classes;
}
add_filter( 'body_class', 'custom_body_classes' );

So I will have to write my own stylesheets, and target .term_name .class_to_target
This is ok. If a better solution comes about I will post it here, as applying templates seems to be a regular question.

2 Likes