Site logo

Archived topic

Create a contained one column layout in the PHP template?

5 replies · Started by Henry on April 8, 2023

Viewing posts 1–6 of 6

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!

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!

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!

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/

Good job!

It worked :)

Thanks

You are welcome :)

This archived topic is closed to new replies.