This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

PHP verus Template Builder templates

  • Creator
  • #23370

    Hi Jason,

    No rush on this, but I get asked a lot about when to use the Template Builder and when to create a custom content part or custom PHP template.

    Here’s a case:

    Design calls for a Custom Post Type = Attorneys

    Single Post Template needs a title and image that displays across the top of the content/sidebar. The content consists of 2/3 column with the_content plus 1/3 column for a bunch of custom fields (no widgets).

    The student replicated the Portfolios plugin and changed it to be Attorney. (She had several custom post types she was creating, and I thought making a version of the Portfolios plugin would be best as then she could take advantage of the JS integration already though through with the Portfolios plugin.)

    She then built a custom Template in the Template Builder that did everything she needed it to do using the ACF (Advanced Custom Field) shortcode for the cf values in a Content Element. Then, on each Attorney post, she chose this Template. The hitch? Well, the html she was using before the custom fields for labels outputs regardless of whether there is a value for the cf. She needed these to conditionally show instead.

    What I told here was this:

    1 – I would set the Sidebar Layout to Full Width in Theme Options for this CPT.

    2 – I would create a custom content-____.php part to handle the Title, large image, and columns for the content and conditional custom fields.

    My general inclination is create a custom content part if working with true template needs with posts and custom post types and reserve the Template Builder for more unique layout needs for pages. I guess I’m still feeling like not overusing the Template Builder. I think it create more steps and possibly more queries. What are your thoughts and opinions? I know we can load our own Elements into the Builder or even create our own shortcodes to use with her ACFs, and that would be one way to deal with her custom field conditionals, but still seems like more work than creating a custom content part, imho. Not to mention that the client has to select the Template Builder template on every post they create.

    That all being said, I’m wondering if you might do more with Custom Field Element in the future to add functionality to have “before” and “after” html that only output if the CF had a value? That would truly be awesome.

    Anyway, please let me know if there’s something obvious I haven’t thought of or missed! I do want to give people some good guidelines, because most of my students are coming from zero template experience. I’m also trying to get people more familiar with the ACF plugin and Pro version for different template needs. I’m also a bit Zen in my approach (simpler is better) and conservative about using the Template Builder. That’s not to say I haven’t been going crazy gangbusters with the new Template Builder Elements myself!!!


Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #23381
    Jason Bobich


    If it were me, I would be creating a content-*.php file for my custom post type and setting it up that way. What you’re describing of using the layout builder for this seems like a bit of a crutch to avoid child theme development.

    Although it will work, this is not what the layout builder is designed for. It’s much more efficient on the loading of your posts, to not have the posts being comprised of a custom layout. I think that if you were to use the layout builder as a template for a custom post type, there should be a purpose behind it.

    For example, maybe the “template” uses things that are more easily managed through the builder, like complex elements with a lot of options, or something that needs to be edited often by the user. But if you’re just trying to throw up columns and a few simple elements, I’m not really sure it’s worth it.

    That all being said, I’m wondering if you might do more with Custom Field Element in the future to add functionality to have “before” and “after” html that only output if the CF had a value? That would truly be awesome.

    If I’m understanding you, this is already possible. When any element loads, this is the basic structure that outputs:

    action hook: themeblvd_element_{element}_before
    <div class="element element-{element}">
    	action hook: themeblvd_element_{element}_top
    	Output element ...
    	action hook: themeblvd_element_{element}_bottom
    action hook: themeblvd_element_{element}_after

    So, you’d probably do something like this:

     * The top of the custom field element.
    function my_element_custom_field_top( $id, $options ) {
    	$val = get_post_meta( themeblvd_config('id'), $options['key'], true );
    	// ...
    add_action('themeblvd_element_custom_field_top', 'my_element_custom_field_top', 10, 2);
     * The bottom of the custom field element.
    function my_element_custom_field_bottom( $id, $options ) {
    	$val = get_post_meta( themeblvd_config('id'), $options['key'], true );
    	// ...
    add_action('themeblvd_element_custom_field_bottom', 'my_element_custom_field_bottom', 10, 2);

    Thanks! That validates what I have been telling people. I do think there is a tendency to use the Template Builder as a crutch, so I am trying to educate people about when and when not to use the Template Builder. Even my PHP savvy students seem to want to use it when it’s really not the best solution, because they think they can.

    I will play with the themeblvd_element as that might come in handy with very specific things. I haven’t come across a need yet, but I’m sure it will happen.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.