Site logo

[Resolved] Create a contained one column layout in the PHP template?

Home Forums Support [Resolved] Create a contained one column layout in the PHP template?

Home Forums Support Create a contained one column layout in the PHP template?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2602650
    Henry

    I assign full-page or two-column layouts based on the Elements > Layout option which works great, i.e. you just assign the page type, etc and it assigns the correct layout.

    However, I have a Custom Taxonomy that does NOT appear in the “Display Rules” dropdowns…

    So, I am left with customizing the PHP Template; – so – my question is – how can I make the PHP Template full width or contained as ONE column just using PHP.

    Hope that’s clear!

    Thanks!

    #2603271
    Ying
    Staff
    Customer Support

    Hi Henry,

    However, I have a Custom Taxonomy that does NOT appear in the “Display Rules” dropdowns…

    Custom taxonomies should’ve shown in the display rule.

    Do you only have more than one custom taxonomy? If so, are other custom taxonomies showing up in the display rule?

    If you only have one custom taxonomy, can you attach the settings of the custom taxonomy?

    Let me know!

    #2605592
    Henry

    Thanks for helping…

    Hmmm..I am using a popular WP Plugin called CPT UI for the Custom Post Type/Taxonomies…now, if I associate my Custom Taxonomy with the WP Core Pages (for example) then yes, it does appear in the GeneratePress elements dropdown. HOWEVER, the dropdown lists the posts one by one and I can’t select “ALL”.

    TBH, I think a faster solution is just to modify the PHP template itself….

    Is there anything I can place in the header or body tag that can force the template to be one column?

    Thanks!

    #2606023
    Ying
    Staff
    Customer Support

    In that case, try the following steps:

    1. create a layout element for the custom taxonomy, do NOT assign any location, publish it.

    2. Add this PHP code, change 1000 to the actual element id (you can find it in the URL of the element editor), change my_cpt to the post type you want to apply to, change my_custom_tax to the actual custom taxonomy slug.

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        global $post;
    
        // Check if the current post is of the custom post type "my_cpt"
        if (1000 === $element_id && 'my_cpt' === get_post_type() ) {
    
            // Check if the current post has any term assigned to the custom taxonomy "my_custom_tax"
            if ( has_term( '', 'my_custom_tax' ) ) {
                $display = true;
            } else {
                $display = false;
            }
        } else {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #2606827
    Henry

    Good job!

    It worked 🙂

    Thanks

    #2607594
    Ying
    Staff
    Customer Support

    You are welcome 🙂

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