Cyber Week Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

[Resolved] Make Masonry work for Custom post types

Home Forums Support Make Masonry work for Custom post types

Viewing 15 posts - 1 through 15 (of 35 total)
  • Author
    Posts
  • #168605
    Susanne Friedrich

    Hi There,
    I have installed the portfolio post type plugin and the GP-premium plugin and would like to have my portfolio posts ( or any other custom post types i might create) display in masonry style.

    Do I have to create a archive-portfolio and single-portfolio template to do that or is there a way to ad a function. Right now only my regular posts display in masonry style.
    Any input appreciated
    Thanks
    Susanne

    #169403
    Susanne Friedrich

    Hello hello anyone out there?

    #169706
    Susanne Friedrich

    ok just want to share that I have found a way to make it work, but only by changing the original plugin.
    I opened the masonry.php file in generate-blog/functions and changed
    this line (13)

    // If we're not dealing with posts, set it to false	
    	$masonry = ( 'post' == get_post_type() || is_search() ) ? $masonry : 'false';
    
    to this // If we're not dealing with posts, set it to false	
    	$masonry = ( 'post' == get_post_type() || is_search() ) ? $masonry : 'true';

    and voila, I now have masonry in all of my custom post types.

    Of course I would like to do this in my child themes function file instead. That’s next on the agenda. will report back

    #170834
    Tom
    Lead Developer
    Lead Developer

    Hi Susanne,

    I’m so sorry – I have no idea why I wasn’t notified of these posts. Time to look in my email error logs to see what’s going on.

    Good news, the function you edited is filtered, meaning you can adjust it in your child theme.

    For example:

    add_filter( 'generate_blog_masonry','generate_adjust_masonry' );
    function generate_adjust_masonry( $masonry )
    {
        if ( 'your-post-type' == get_post_type() ) :
            return 'true';
        endif;
    
        return $masonry;
    }
    
    add_filter( 'generate_blog_activate_masonry','generate_activate_posttype_masonry' );
    function generate_activate_posttype_masonry()
    {
        $masonry = 'false';
    
        if ( is_home() || is_archive() || is_search() || is_attachment() || is_tax() )
    	$masonry = 'true';
    
        if ( 'your-post-type' == get_post_type() )
            $masonry = 'true';
    
        return $masonry;
    }

    Give that a shot and let me know how it works 🙂

    • This reply was modified 4 years, 10 months ago by Tom.
    • This reply was modified 4 years, 10 months ago by Tom.
    • This reply was modified 4 years, 9 months ago by Tom.
    • This reply was modified 4 years, 9 months ago by Tom.
    • This reply was modified 4 years, 9 months ago by Tom.
    • This reply was modified 4 years, 9 months ago by Tom.
    • This reply was modified 4 years, 9 months ago by Tom.
    #171371
    Susanne Friedrich

    Hi Tom,
    Thanks so much for taking a look at this, I tried your filter in my child theme functions.php file.
    This is what I put in:

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

    Unfortunately the entire site blanked out. This happens sometimes if I add something in functions that has some type of error in it. in firefox it says: The connection to the server was reset while the page was loading.

    The site could be temporarily unavailable or too busy. Try again in a few moments.
    If you are unable to load any pages, check your computer’s network connection.
    If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

    Any idea where the error might be?

    #171455
    Tom
    Lead Developer
    Lead Developer
    #171513
    Susanne Friedrich

    Hi Tom,
    Thanks for the update, I see that you added the $ before masonry.
    I used that code and got the same error message.
    Any other ideas.? I am trying to learn all about filters and actions.

    Thanks
    Susanne

    #171607
    Tom
    Lead Developer
    Lead Developer

    Interesting – do you have access to your server error_log file? If so, can you see if there’s a specific error in there?

    If not, can you get your hosting tech support to take a look at the file?

    #171652
    Susanne Friedrich

    Hi Tom, yes I am developing on Mamp, error log file says ( among other things):
    2/9/16 3:29:52.446 PM Console[22121]: Failed to connect (_consoleX) outlet from (NSApplication) to (ConsoleX): missing setter or instance variable

    Exception Type: EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes: KERN_PROTECTION_FAILURE at 0x00007fff5f3ffe5c

    #171689
    Tom
    Lead Developer
    Lead Developer

    Hmm, that doesn’t look like anything related to the code.

    Do you have another site not on MAMP that you can test the code on?

    #171708
    Tom
    Lead Developer
    Lead Developer
    #171745
    Susanne Friedrich

    Thanks so much for bearing with me Tom.
    We are getting closer! the page is displaying now. However: the code just adds a class of “masonry-post” to the article, but none of the masonry classes to the containing elements.
    Here is a live site, so you can take a look: http://www.sanneart.com/blog/
    I have made the blog display in masonry.
    My custom post type is portfolio.(link next to blog)
    I added this to my child theme functions:

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

    This is showing me a few things I need to clean up to make this process easier, so thanks for bearing with me! 🙂

    Can you try the updated code now?: https://generatepress.com/forums/topic/make-masonry-work-for-custom-post-types/#post-170834

    #171852
    Susanne Friedrich

    Thank You for doing this!
    OK I uploaded the revised code. Still looks the same

    #171867
    Tom
    Lead Developer
    Lead Developer

    What a mess this function is 🙂 I’ll be cleaning it up in the next update and will update this thread with the (much more simple) code you can use.

    For now, try this: https://generatepress.com/forums/topic/make-masonry-work-for-custom-post-types/#post-170834

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