[Resolved] Make Masonry work for Custom post types

Home Forums Support [Resolved] Make Masonry work for Custom post types

Home Forums Support Make Masonry work for Custom post types

  • This topic has 34 replies, 5 voices, and was last updated 8 years ago by Tom.
Viewing 15 posts - 16 through 30 (of 35 total)
  • Author
    Posts
  • #171889
    Susanne

    Well the plot definitely thickens:)
    I used the latest code and don’t really see a change in the archive, however the single post now shows very small images. See it on my website)
    This could be because i am using a plugin called jquery-masonry-image-gallery. It might conflict with the display of the gallery images.
    However on my other local install I see the styling of the masonry applied to the archive. So it is targeting it.
    Would it be possible to just create a custom archive-portfolio and put the masonry function in there?

    #171964
    Tom
    Lead Developer
    Lead Developer

    I’m not seeing any single posts with small images? Do you have a direct link?

    I’m confused as to why the filter isn’t targeting the post type.

    Any chance you can send me temporary admin login details to support@generatepress.com?

    #172025
    Susanne

    yes i sent you a pw just now
    here is the url for a sample page of tiny post. I think it makes a masonry tile out of the entire page which contains an image gallery with the masonry-image-gallery plugin activated. That’s why I think there might be a conflict. I just want the archive page to show masonry.

    #172209
    Tom
    Lead Developer
    Lead Developer

    Ha, well, this entire issue was a tiny mistake on my part.

    I just adjusted the code and it seems to be working perfectly.

    Let me know πŸ™‚

    #172215
    Susanne

    woohoo!
    You’re a freakin genius! Thanks so much!

    #172225
    Tom
    Lead Developer
    Lead Developer

    You’re very welcome – sorry that it took so long!

    #173111
    Susanne

    Hi There,
    Sorry to bug you again about this issue, but just one little follow up on this:
    Apparently the function makes the single portfolio also have a masonry layout. which I only want in the archive
    here is a screenshot from my local install
    http://www.sanneart.com/single-portfolio.png
    Can we fix that?
    Thanks so much

    #173121
    Susanne

    ok update, I have found the solution: instead of saying

     if ( 'portfolio' == get_post_type() )
            $masonry = 'true';

    I changed it to

     if ( is_post_type_archive( 'portfolio' ) )
            $masonry = 'true';

    and that gives me the correct result!

    #173160
    Tom
    Lead Developer
    Lead Developer

    Nice! Thanks for posting the solution πŸ™‚

    #173209
    Susanne

    so here is another development: I found that the first part of the filter works just fine by itself and has the added advantage to show the single post as it was intended.
    Here is the URL http://www.sanneart.com/portfolio/ and the filter I used

    add_filter( 'generate_blog_masonry','generate_adjust_masonry' );
    function generate_adjust_masonry( $masonry )
    {
        if ( 'portfolio' == get_post_type() ) :
            return 'true';
        endif;
    
        return $masonry;
    }

    My last question ( I promise) is: how can I add the other post types to this as an array. I also have products and effects as post types? Thank you for your never-ending patience

    #173226
    Tom
    Lead Developer
    Lead Developer

    In the new version I adjusted the generate_blog_masonry filter and removed the second one altogether. If you’d like to test it shoot me an email to support@generatepress.com πŸ™‚

    More post types can simply be added to the function:

    add_filter( 'generate_blog_masonry','generate_adjust_masonry' );
    function generate_adjust_masonry( $masonry )
    {
        if ( is_post_type_archive( 'portfolio' ) ) :
            return 'true';
        endif;
    
        if ( is_post_type_archive( 'news' ) ) :
            return 'true';
        endif;
    
        if ( is_post_type_archive( 'events' ) ) :
            return 'true';
        endif;
    
        return $masonry;
    }
    • This reply was modified 8 years, 5 months ago by Tom.
    #173824
    Susanne

    excellent. You are the best. I will definitely like to test out the new theme as I have another site in development right now. Thank you!

    #174729
    Hans Christian Siller

    Hey Tom,

    I just had the same issue – making masonry work for custom posts… Superglad to see you have been working on this and are simplifying this in future versions!

    I’ll be looking into the code you provided in more detail tomorrow. One suggestion though as you plan the changes for the next versions: one really awesome feature is the variable size of the masonry layout – ie. having the first post bigger, and manually assigning sizes (in masonry post width, and by setting a post to “featured” status). Can you think of a way of enabling that functionality (different sizes) for custom posts as well? That would be so *awesome*…

    Ofc, we would then need to hack the editor to display the masonry post width options for custom posts as well. But I have no idea how to do that/if that’s easily possible.

    #174854
    Tom
    Lead Developer
    Lead Developer

    That actually shouldn’t be too hard to do:

    add_filter( 'generate_blog_masonry_metabox','generate_more_masonry_types' );
    function generate_more_masonry_types()
    {
        return array( 'post', 'post-type-here', 'another-one' );
    }

    Let me know πŸ™‚

    #182401
    Fabrizio Lazzeretti

    Hi Tom,
    i’m stuck too with masonry and custom post type.
    I’d like to have masonry on archive and search page, but not in the single article, which at the moment displays with the “medium” column.

    i’m using your code:
    https://generatepress.com/forums/topic/make-masonry-work-for-custom-post-types/#post-170834

    thanks for any help.

Viewing 15 posts - 16 through 30 (of 35 total)
  • You must be logged in to reply to this topic.