Site logo

Archived topic

How to create a page template with a different container width?

5 replies · Started by Silvio on January 19, 2019

Viewing posts 1–6 of 6

Hi,

I am interested in creating a website with:

- narrow container, say 600px
- special landing page with full width for images and contained wide width, say 1000px, for text

I am wondering if I can use sections with a specific class for those sections I want to have a different container width.

Could you help telling how to define the specific class?

I mean, should I write some like

body .specificclass .grid-container {max-width:1000px}

Or

body .specificclass .grid-container {padding: 3% 10%}

Or, would it be better to use a specific page template? How to write it?

Hi Tom,

Yes I did, but here I have three options:

- default, aka contained with padding for the container
- full width
- contained, aka container without padding

If I have a container of 600 px with a 20px of padding, there's no way to have a container larger than 640 px. So, I am considering changing the default container width with a class to add to every specific element of the page, build with sections.

Alternatively, and It seems even simpler, I should create a page template that make use of a body class to set the container to a larger widht, say 1000px.

Which is, in your opinion, the best alternative?
How can I put that in pratice?

Thanks in advance

You could use a custom field to add that body class.

For example:

add_filter( 'body_class', function( $classes ) {
    if ( is_singular() ) {
        $template = get_post_meta( get_the_ID(), 'your_custom_field_name', true );

        if ( $template ) {
            $classes[] = 'my-special-template';
        }
    }

    return $classes;
} );

Then you could use the .my-special-template class without needing to create a page template.

it's not perfectly clear to me how do you do.

so, I add a custom field to the page / post I want to have a different template, for example your_custom_field_name and value true

that way, the class my-special-template is added to the list of the body class?

then, how do I adjust the width of the post / page?

will this rule work?

my-special-template .grid-container {max-width:1000px}

to be honest, to have a page template that uses a different page width seems to me the simplest way to get there. could you point to a guide to create a custom page template for generatepress, so to evaluate which is the simplest way?

This archived topic is closed to new replies.