Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Resolved] GP 1.5 – masonry on blog, columns in CPT archive

Home Forums Support GP 1.5 – masonry on blog, columns in CPT archive

  • This topic has 9 replies, 2 voices, and was last updated 3 years ago by Tom.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #418936
    wekhter

    First off, I’m loving all the new options for archive layouts in the latest GP update. I’m especially glad to see an option to use masonry + pagination instead of only endless scrolling! There’s just one issue, though: I had been using the following code to make it so that I could use masonry on the blog archive, and columns on my CPT archives.

    // Disable masonry on animation CPT
    add_filter( 'generate_blog_masonry','generate_adjust_masonry' );
    function generate_adjust_masonry( $masonry )
    {
        if ( !is_woocommerce() && ( is_post_type_archive() || is_tax() ) ) :
            return 'false';
        endif;
    
        return $masonry;
    }
    
    // Enable columns on animation CPT
    add_filter( 'generate_blog_columns','generate_adjust_columns' );
    function generate_adjust_columns( $columns )
    {
        if ( !is_woocommerce() && ( is_post_type_archive() || is_tax() ) ) :
            return true;
        endif;
    
        return $columns;
    }

    With the new changes to columns/masonry, this no longer works and my CPT uses the same settings as the blog.

    I need the blog to be 2 column masonry + first post featured, and the CPT to be 4 column non-masonry + first post not featured. How do I get that working again?

    GeneratePress 1.4
    GP Premium 1.5
    #418949
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Glad you like the update! Sorry about this, I tried to make everything as backward compatible as possible.

    First, set your blog settings in the Customizer to what you want everywhere.

    Then do this to disable masonry on your custom post type:

    add_filter( 'generate_blog_masonry', 'tu_adjust_masonry' );
    function tu_adjust_masonry( $masonry ) {
        if ( ! is_woocommerce() && ( is_post_type_archive() || is_tax() ) ) {
            return 'false';
        }
    
        return $masonry;
    }

    As for the featured post, nothing in your code above would have affected that. But you can turn it off like this:

    add_filter( 'option_generate_blog_settings', 'tu_adjust_featured_image' );
    function tu_adjust_featured_image( $options ) {
    
        if ( ! is_woocommerce() && ( is_post_type_archive() || is_tax() ) ) {
            $options['featured_column'] = false;
        }
    
        return $options;
    
    }

    Let me know if this helps or not 🙂

    #419005
    wekhter

    @Tom Almost there! I’ve disabled masonry on my CPT now, but how can I set up the number of columns? I need 2 columns in my blog and 4 columns on this CPT.

    Just as a request–it would be great to be able to set this sort of thing up in the options, just like how you’ve added options for archive vs single… post archive, single post, cpt archive, cpt? Archive styling for blogs doesn’t necessarily work for other things, like portfolio archives (as an example). It could be a very helpful addon, similar to the woocommerce addon.

    #419006
    Tom
    Lead Developer
    Lead Developer

    This should help for setting the number of columns: https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns

    It’s hard to add options for this, as there can be an infinite number of CPTs on a site. That’s what filters are for 🙂

    #419020
    wekhter

    @Tom Getting closer in that I can set the columns to the correct width I want, but it seems that once I enable columns masonry is automatically applied as well, whether or not I have the snippet that sets masonry to false, so even though the blocks are 25% width, they’re absolute positioned into 2 columns from the masonry script.

    And gotcha, I figured it was a long shot request 🙂

    #419023
    Tom
    Lead Developer
    Lead Developer

    Can you link me to that page possibly?

    #419036
    wekhter

    @tom Here you go: http://unsightly-gerbil.w3.poopy.life/animation/ It’s my test site so don’t mind the general mess. As you can see, I’ve set it to be 25% width columns, but the masonry script is taking over placement.

    #419050
    Tom
    Lead Developer
    Lead Developer

    Let’s do it a little differently.

    Turn masonry off in the Customizer.

    Then do this:

    add_filter( 'generate_blog_masonry', 'tu_adjust_masonry' );
    function tu_adjust_masonry( $masonry ) {
        if ( is_home() ) {
            return 'true';
        }
    
        return $masonry;
    }
    #419627
    wekhter

    @Tom All working perfectly now, thanks!

    #419630
    Tom
    Lead Developer
    Lead Developer
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.