Site logo

Archived topic

Make Masonry work for Custom post types

34 replies · Started by Susanne on January 28, 2016

Viewing posts 1–15 of 35

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

Hello hello anyone out there?

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

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 :)

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?

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

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?

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

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?

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;
}

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

This archived topic is closed to new replies.