Updated on September 18, 2020
Masonry is a JavaScript grid layout library. It works by placing elements in optimal position based on available vertical space, sort of like a mason fitting stones in a wall.
In this tutorial we are going to apply Masonry for Posts page and all archives in Genesis.
While the tutorial has been written for Genesis Sample 3.3.1 (and Genesis 3.3.3), it should work with a few adjustments in any Genesis theme.
Step 1
Add the following in child theme's functions.php
:
// Registers a custom image size for image thumbs on content archives.
add_image_size( 'masonry-image', 500, 0, true );
Step 2
Create a directory named js
in the child theme directory.
Inside that, create a file named say, masonry-init.js
having the following code:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
Hey, thanks Sridhar! This solution may work. I tried it. My child theme is the Dynamik Website Builder, which already has a home.php. I’m unsure if I should try to merge the two home.php files or what.
Love masonry, though, so it would be nice to get this to work on my blog template! Thanks again for your work.
Thanks for this update! I’m using this on one of my sites and might have been very lost to see my masonry stop working suddenly (had I updated immediately). I’m inserting a .entry “grid-sizer” to allow for some full-width posts across the top, and just needed to update my .js and change the CSS of my grid-sizer. Can’t have display: none on your first item anymore.
Good stuff Sridhar !
About to start a new theme that uses masonry too, impeccable timing 🙂
Dear Mr. Sridharkatakam, what a great Tutorial. I used it today on my theme and it worked out just perfect. NOW I have two questions: 1. is it possible to show the latest post thumbnail bigger than the older posts? 2. Ist it possible to define 1 (or more) thumbnails to always show ?
Thank you very much!!! regards, AoVoKo
I cannot seem to get my pages post (“articles”) that uses the blog template to display more than 1 column.
I’m getting the masonry effect, but it’s only one column, leaving the entire 3/4 of the right-hand side of the page blank.
Any guidance in this regard would be greatly appreciated!
Hi Jason, I had the same Problem … I then used the “old” version of this Tutorial… and removed the infinite scroll. Than I calculated the maximum width of the pictures as shown in the tutorial.. the wider they are the less coluns you will have… and voila- it worked out!!! I hope this helps?
The only problem I am still having now is, that it does not show the possibility to go back on older posts… If anyone could help with this?
Thanks for the advice, AoVo.
I believe things are different for the Dynamik child theme. If you have a static homepage in Dynamik, you have to set your reading >> settings to show your latest posts — not a static homepage.
I therefore cannot alter my blog template by putting my posts page as blog.
I have tried reducing the width to 155 pixels even on a standard Genesis child theme, and again, I get the Masonry effect, but it’s just one column.
Sridhar does a wonderful job … but I’m not sure this is a one-size-fits-all solution to the Masonry effect, as I’ve tested on 2 separate child themes and still get just 1 column.
Hi Sridhar,
Thank you for the masonry code, I have tried it out and it looks great. How would I got about creating a page template that allows me to use a sidebar with the masonry layout?
Many thanks
Tim, london
Thank you so much Sridhar, this is a brilliant tutorial. You are definitely my favorite Genesis expert.
Two questions to anyone who can help me. I am fairly new to WP/Dev
1. If I wanted to pull a masonry feed onto my front-page template, how would i go about doing that with this method? (parallax pro is my base.)
2. Additionally, how hard would it be to create varying size blocks? I would like my grid to be able to include different size blocks.
Any info, tips or suggested reading on the above questions is appreciated.
Thank you.
Hi
Thanks for the great tutorial.
I have the same 2 questions (Front page and different size blocks).
Can you direct me to the solution?
Rani
Hi Sridhar,
Great post! Used it on my website and works fine. How would I go about adding a toggle function to let the user switch from masonry view to standard list view using same template?
Thanks!
Claude
while back i saw a tut on making the masonry heights even using some js framework.
unfortunately, i did not save it or bookmark it. are you aware of that js that helps to make the heights even up?
This is awesome Sridhar but! How do we show JUST the post title & photo only? Your assistance would be greatly appreciated! 🙂
Also – images aren’t showing up for me at all. I set “Featured Image” and insert the image in the post and it doesn’t show up like you example above.
Hi Sridhar,
Nice post. Would you please tell me how to insert banner in specific post. Let me clear i want to see a banner after 5 post.
Thanks,
Sajib Roy.
[…] the past I wrote about setting up Masonry in Genesis here. In that article I provided the code to display blog posts in Masonry Grid on the Posts page […]
Hi,
thanks for a great tutorial.
If you initialize infinite scroll with this new masonry setup there are errors, such as a single column for page 2 and beyond content.
This has something to do with the JavaScript in masonry-init.js. Using your original masonry-init.js from Using Masonry in Genesis for a Pinterest like layout fixes this issue. Can you explain why that’s the case?
Thanks
Haha,
I just realized that infinite scroll is a jQuery plugin and therefore we have to initialize it with jQuery. Is there another way to combine masonry with infinite scroll? How about making this masonry setup compatible with Jetpack infinite scroll?
Thanks
How do I just have the post image display?
Hi. I was wondering if this could also work in custom post type?
Is it possible to add a border to some posts but not all? Have tried .post-id .masonry-page .content .entry etc. This does not seem to work. Thanks.
Wow, that was fast and specific. Another successful implementation of your tutorial. You can see it here:
https://heliopatch.com/power-through-blog/
I’d love to show the blog title (page title for the blog), but can’t seem to get that to work. Has anyone?
Try these steps:
1) In functions.php add http://pastebin.com/raw/acVaQXM5
2) In style.css add http://pastebin.com/raw/KzpS8rTQ
http://d.pr/i/168E5
Thank you, Sridhar. Worked like a charm.
Sridhar,
Did you ever find a way to show the page title in the theme’s provided site title area (or the archive title within the theme’s site title)?
Specifically, showing the title show here:
https://heliopatch.com/power-through-blog/
Like this:
https://heliopatch.com/contact/
Without having this duplicate:
https://heliopatch.com/category/science/
(You probably recognize it, that’s a slightly modified Centric Pro)
Yes.
1) Follow/implement the steps in https://sridharkatakam.com/repositioning-titles-centric-pro/
2) In archive.php delete http://pastebin.com/raw/P0JWAV5U
Thank you, thank you, thank you. Your giving kindness is humbling.
Thank you again. Worked like a charm. See it here: https://heliopatch.com/the-naked-electron/
Ran into a bit of a challenge with a “duplicate” page-title class. Figured it out with some CSS.
[…] Do not follow the tutorial below. Follow https://sridharkatakam.com/masonry-genesis/ […]
Hi Sridhar!
I’ve updated my theme since the other version wasn’t working properly, for some reason I can’t make work the media queries for iPads, it only shows one article per row, instead of two. Any suggestion?
http://mairagall.com/demos/gazette/
Thanks,
Maira
In your media queries I see that you are setting width only for
.masonry-page .content .entry
. You need to set the same width for.grid-sizer
as well.For example in the 900px media query
[css].masonry-page .content .entry {
width: 40.917948717949%;
}[/css]
should be
[css].grid-sizer,
.masonry-page .content .entry
{
width: 40.917948717949%;
}[/css]
Can you make this change and let me know when done?
Yep, that’s it. I noticed the .grid-sizer selector was missing but when I added it via the inspector it didn’t change anything so I thought it wasn’t that.
Thank you very much!
Hi, I have been using the script on a website http://dutchgameawards.nl/2016/category/games-2016/ and it works fine everywhere except for Safari on Mac. There the initial load is not correct. After clicking on any of the categories or the ‘all’ button the lay-out is right again.
I see the same happening on the site that NandoJourneyman posted above here.
https://heliopatch.com/power-through-blog/
Do you know a solution to this?
I don’t see the problem at https://heliopatch.com/power-through-blog/ in Safari on my Mac.
I do see it at http://dutchgameawards.nl/2016/category/games-2016/.
Try enqueuing ImagesLoaded and setting it as a dependency for Masonry like this:
Upload https://github.com/desandro/imagesloaded/raw/master/imagesloaded.pkgd.min.js to child theme’s
js
directory.Then change
to
[…] Masonry in Genesis tutorial is now available as a functionality theme. […]
Using Infinity Pro on a dev site (http://www.custompageapps.com/blog/)
I want to remove everything but the title and featured image. Not sure how to do that.
Can you help?
I’ve been playing with the .php (not that I know better) and i think I have it except for the double divider lines below each post – How do I get rid of the dotted one?
Try adding
inside the
sk_masonry_layout()
.Just did that but no change.
// Display Post thumbnail, Post title, Post content/excerpt, Post info and Post meta in masonry brick.
add_action( ‘genesis_meta’,’sk_masonry_layout’ );
function sk_masonry_layout() {
if ( is_singular() || is_search() ) {
return;
}
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
add_action( 'loop_start', 'sk_grid_sizer' );
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
add_action( 'genesis_entry_content', 'sk_masonry_block_post_image', 8 ) ;
add_action( 'genesis_entry_content', 'sk_masonry_title_content', 9 );
add_action( 'genesis_entry_footer', 'sk_masonry_entry_footer' );
add_filter( 'genesis_post_info', 'sp_post_info_filter' );
remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
add_action( 'genesis_before_content', 'genesis_do_breadcrumbs' );
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
add_action( 'genesis_before_content', 'genesis_do_taxonomy_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
add_action( 'genesis_before_content', 'genesis_do_author_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_author_box_archive', 15 );
add_action( 'genesis_before_content', 'genesis_do_author_box_archive', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
add_action( 'genesis_before_content', 'genesis_do_cpt_archive_title_description' );
remove_action( 'genesis_before_loop', 'genesis_do_search_title' );
remove_action( 'genesis_before_content', 'genesis_do_search_title' );
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' );
add_action( 'genesis_after_content', 'genesis_posts_nav' );
remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );
remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );
}
I provided/pasted the wrong code in the earlier comment by mistake.
Try adding this CSS:
How would I use this as a page template i.e. name it archive.php?
Do you want to implement this on all archive pages and on the Posts page?
Yes. I’d like this for all archive categories and posts. Is this version not? I notice in the code you exclude singles and search only.
Also for above code I found an issue where title & description gets buried behind. Also run into issues on the 404.
Added !is_404() where you excluded singles and search.
Also added this to fix posts header inside sk_masonry_layout()
remove_action( ‘genesis_before_loop’, ‘genesis_do_posts_page_heading’ );
add_action( ‘genesis_before_content’, ‘genesis_do_posts_page_heading’ );
Also besides being a template just trying to clean up my code. My functions file is 500 lines and scaring me.
I am working on cleaning this up/improving. Will share soon.
Done. Updated the tutorial.
Is it possible to style entries according their categories?
That is not practical because an entry can belong to more than 1 category. Isn’t it?
Or is it that a post belongs to only one category in your site setup?
Thank you for the reply. You are right, this will cause a problem since each entry can belong to more than one category.
Hi Sridhar
I was having the same IE issue with this one as I had with the “Masonry Grid on Content Archives with Title and Excerpt on Hover in Genesis” tut.
I added “float: left;” to “.masonry-page.full-width-content .content” and it fixed it.
Great tutorial. Thanks.
Dom
I’ve tried this multiple times on a new site that I am working on.
The theme is Aspire but I also tried the same on the Sample theme with no luck.
Will this not work post WP5.0?
Here’s the dev site http://symmetrymgmt.wpengine.com/listings/
Listings is a custom post type using AgentPress Listings – thought that might be the issue so I also created a couple of blog posts and it’s the same: http://symmetrymgmt.wpengine.com/blog/
Any Ideas?
Updated the tutorial.