Site logo

Archived topic

Used different number of columns for Blog and Archive pages

5 replies · Started by Alan on May 24, 2020

Viewing posts 1–6 of 6

I want to use two columnns with a sidebar for my main blog page and three columns without a sidebar for my category, tag, and author archive pages. Is this possible? In the customizer, there is only one columns setting...

David:

Please forgive me, but I am new to Generate Press and not a developer. I followed your instructions and created a snippet with the following code:

add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ( is_search() ) {
$options['read_more_button'] = false;
$options['date'] = true;
$options['categories'] = false;
$options['tags'] = false;
$options['comments'] = false;
$options['infinite_scroll'] = true;
$options['infinite_scroll_button'] = true;
$options['masonry_load_more'] = 'More search results';
$options['post_image'] = true;
$options['post_image_position'] = 'post-image-above-header';
$options['post_image_alignment'] = 'post-image-aligned-center';
$options['column_layout'] = true;
$options['featured_column'] = false;
$options['masonry'] = false;
}

return $options;
}

It produced an error message as follows:

The snippet has been deactivated due to an error on line 3:
Cannot redeclare function lh_custom_search_results_page_settings.

What should the code be for line 3? As previously stated, my goal is to have the archive pages return three columns while the main blog page remains at two columns.

Thanks,

Hi there,

Instead of that function, do this:

add_filter( 'generate_blog_get_column_count', function( $column_width ) {
    if ( is_front_page() ) {
        return '50';
    }

    return $column_width;
} );

That will make it so your home page has two columns, and the rest of your site will use the option set in the Customizer.

As for the sidebar, the Layout Element is the best way to go: https://docs.generatepress.com/article/layout-element-overview/

What would be the function if I am displaying my posts on the blog page, rather than the home page?

In Tom's code you would change:

is_front_page()

to

is_home()

This archived topic is closed to new replies.