Site logo

Archived topic

Putting coments area in its own container without affecting blog archive page

3 replies · Started by Bandara on April 2, 2021

Viewing posts 1–4 of 4

I like the look of my single post pages when Content Layout is set to separate containers In particular I like the comments to be in their own container.

However, after I changed to separate containers, the archive page layout changed so that there is extra padding around the featured images and there is no longer a background behind them. Please see attached images.

Is there a way to change the content layout to separate containers without changing the look of the archive page?

Hi there,

We can target where we can apply separate container or one container with PHP snippet with option_generate_settings filter. https://docs.generatepress.com/article/option_generate_settings/

example: Say, we want one container on posts but separate container on archive, we can do it with this code.

add_filter( 'option_generate_settings','lh_single_posts_settings' );
function lh_single_posts_settings( $options ) {
    if ( is_single() ) {
        $options['content_layout_setting'] = 'one-container';
    } if ( is_archive() ) {
        $options['content_layout_setting'] = 'separate-containers';
    }
    
    return $options;
}

Or if you want ALL archives and pages to be separate container except for posts, you can set "separate container" on the customizer settings and do this:

add_filter( 'option_generate_settings','lh_single_posts_settings' );
function lh_single_posts_settings( $options ) {
    if ( is_single() ) {
        $options['content_layout_setting'] = 'one-container';
    } 
    
    return $options;
}

Great! that worked.

So will this override anything I set in the Customizer? It looks like maybe that help doc was written for the free theme?

Thank you!

Hi there,

1. No - the Customizer Container layout settings still apply globally.
Elvins codes then says 'but not for the Single ( any post type excluding Pages and Attachments )' or 'Not for my Archives'.

So reading through your topic. If you want only the Single Posts to be Separate Containers, then:

a. Set the Customizer to one Container.
b. Add this snippet:

add_filter( 'option_generate_settings','lh_single_posts_settings' );
function lh_single_posts_settings( $options ) {
    if ( is_single() ) {
        $options['content_layout_setting'] = 'separate-containers';
    } 
    
    return $options;
}

Now then entire site will be One Container except for your Single Posts.

2. the filter being used in that PHP Snippet is in the Theme - it makes no difference if you have the GPP Premium plugin enabled.

This archived topic is closed to new replies.