Site logo

Archived topic

Blog Masonry different layout for Blog front page and for Archives

12 replies · Started by Roman on June 23, 2017

Viewing posts 1–13 of 13

Just wandering if it is achievable to have slightly different layouts for 1. Blog front page and for 2. Archive pages, for example:

1.
Masonry Block Width – medium
Masonry Most Recent Width – large

2.
Masonry Block Width – medium
Masonry Most Recent Width – medium

Tough question! Try this (untested):

add_filter( 'generate_masonry_post_width', 'tu_custom_masonry_width' );
function tu_custom_masonry_width( $width ) {
    global $wp_query;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    if ( is_home() ) {
        if ( $wp_query->current_post == 0 && $paged == 1 ) {
            return 'width6';
        } else {
            return 'width4';
        }
    }

    if ( is_archive() ) {
        return 'width4';
    }

    return $width;
}

Well, it does not work, only one column is displayed. Maybe because I use content/sidebar/sidebar for is_home() and content/sidebar for is_archive().

Thanks

Can you link me to each respective page?

I am still testing on local host. I am about to go online. As soon as my site is online I will post a link here for you.

Thanks

It doesn't look like masonry is turned on.

Sorry, I forgot I don't use masonry due to lazy loading issues. Can you please modify a/m filter for columns?

You could try this:

add_filter( 'generate_blog_get_column_count', 'tu_custom_columns_width' );
function tu_custom_columns_width( $width ) {
    global $wp_query;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    if ( is_home() ) {
        if ( $wp_query->current_post == 0 && $paged == 1 ) {
            return 'featured-column';
        } else {
            return 50;
        }
    }

    if ( is_archive() ) {
        return 50;
    }

    return $width;
}

Ok, since we're just wanting to remove the featured column on any page but the home page, we can do this instead:

add_filter( 'post_class','tu_remove_featured_column' );
function tu_remove_featured_column( $classes ) {
    if ( ! is_home() ) {
        $classes = array_diff( $classes, array( 'featured-column' ) );
    }
	
    return $classes;
}

Thank you!

You're welcome :)

This archived topic is closed to new replies.