Archived topic
Applying Masonry to custom page template
6 replies · Started by Peter on April 10, 2017
Hi,
I would like to apply the masonry layout to a custom page template. I found this old post from 2015 https://generatepress.com/forums/topic/masonry-issues-on-custom-page-template/, but it's referencing a blog template that doesn't seem to exist anymore. The pastebins are expired, too.
Could you please explain what I need to do to get this working?
Thanks
Sibylle
Hi Sibylle,
Give this a shot: https://generatepress.com/forums/topic/enable-masonry-on-other-post-types/#post-111604
Let me know if this helps.
The latest code can be found in the docs: https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-masonry-to-your-custom-post-type
Thanks for your suggestions.
Tom, would this work on page templates as well as posts, i.e. like so:
add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
function tu_portfolio_masonry( $masonry )
{
if ( is_page_template('my-custom-template.php') ) :
return 'true';
endif;
return $masonry;
}
And what would I have to add to the page template itself? This is what I have https://pastebin.com/bB6r2PMd
The code looks good. Give it a shot.
Thanks, Leo. I seem to have managed it by removing my div around the article loop in the template and adding the classes masonry-post to the article and inside-article to the inner div.
Is that the correct way to do it or should that be handled by the JS?
That function should do all of that for you as long as the main markup in your page template is the same as regular pages.