[Resolved] Blog Masonry different layout for Blog front page and for Archives

Home Forums Support [Resolved] Blog Masonry different layout for Blog front page and for Archives

Home Forums Support Blog Masonry different layout for Blog front page and for Archives

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #338095
    Roman

    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

    #338229
    Tom
    Lead Developer
    Lead Developer

    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;
    }
    #338449
    Roman

    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

    #338560
    Tom
    Lead Developer
    Lead Developer

    Can you link me to each respective page?

    #338577
    Roman

    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

    #360515
    Roman
    #360785
    Tom
    Lead Developer
    Lead Developer

    It doesn’t look like masonry is turned on.

    #367279
    Roman

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

    #367662
    Tom
    Lead Developer
    Lead Developer

    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;
    }
    #367768
    Roman
    #368052
    Tom
    Lead Developer
    Lead Developer

    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;
    }
    #368208
    Roman

    Thank you!

    #368362
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.