Want to display Portfolio Post Type items in Masonry style in Genesis?
In this article I share the code for using Masonry (built into WP) on Portfolio CPT Archive page and Portfolio taxonomy archives on non-handhelds. On tablets and mobiles, :nth-of-type pseudo selector will be used for displaying the entries in a grid with the number of columns depending on viewport widths.
While the tutorial has been written for Genesis Sample child theme it should work with minor adjustments in any Genesis child theme.
Step 1
Install and activate Portfolio Post Type plugin. This will register a portfolio
Custom Post Type with a corresponding portfolio_category
and portfolio_tag
custom taxonomies.
Add your Portfolio entries while setting a featured image for each. Images of varying sizes make the best impact for the masonry display.
Step 2
Create a file named say, masonry-init.js in child theme's js
(create if not existing) directory having the following code:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
Hi Sridhar,
Thanks for the tuturial, it’s great!
I would like to use this with Easy Content Types (by pippins plugins), instead of the Portfolio Post Type plugin, is that possible? And is it possible on a page with a right sidebar?
Thanks in advance,
Eva
Are you going to register and use custom taxonomies with that plugin?
Yes, it is possible to have this on a page with right sidebar. Just delete the following in archive-portfolio.php:
// Force full width content
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
You also need to adjust the width of
.masonry-page .content .entry
.((no. of columns) * x) + ((no. of columns – 1) * gutter width) = available width
Hello Sridhar,
Thanks for your prompt reply. I am still in a testing phase and I don’t know yet if I will need to use taxonomies. The purpose is to show the custom post types to replace this: http://www.xanderuitgevers.nl/, with more or less the same look and feel. Hope that’s possible.
For your information, the description of the plugin says:
“Much like the built-in Categories and Tags, custom taxonomies allow you to define an organization within your custom post types. In just seconds you can add a “Genres” category to your movies or books review website and “categorize” all reviews into their correct Genres. It works just like the regular categories, but is so much better because you get to define the exact name your taxonomy uses.”
I am sorry, but I don’t understand exactly how to use ((no. of columns) * x) + ((no. of columns – 1) * gutter width) = available width
Just change no. of columns?
Thanks again,
Eva
Hi Sridhar,
Thank you very much for the tutorial, I really appreciate it! I’ve applied it and it works well.
I’m only having trouble with the media queries, they seem to display the images like a stair case, or they don’t have a padding between entries. Not sure if I am also the only one experiencing trouble.
I want to be able to reorder the portfolio using the Simple Page Ordering plugins. I’m not sure but where do I add the following code in the functions.php?
$query->set( ‘orderby’, ‘menu_order’ );
$query->set( ‘order’, ‘ASC’ );
Thanks in advance 🙂
look at the functions.php file line 18.
@256studio I added the code to line 18 of the function.php and it does not work.
Hi Sridhar,
I tested out my site on two different tablets (iPad and Nexus 9) and the masonry effects doesn’t show. Instead, it shows up like a grid. Again not sure if this related to the media queries…
.masonry-page .content .entry {
/* ((no. of columns) * x) + ((no. of columns - 1) * gutter width) = available width */
}
Can you help me understand the formula?
What is “X”?
for example if I have 4 columns:
((4) * X + ((4-1) * 40)
Thanks.
x is the width of each masonry block (.masonry-page .content .entry). It depends on how many columns you want, what your desired horizontal gap between blocks is and the width of blocks’ container.
I use Soulver to calculate this. See http://d.pr/i/1g7wK.
Awesome! Thanks very much.
Hi Sridhar,
first of all really great tutorials!
I’ve used this and it works perfekt.
Currently I use the Altitude-Pro childtheme. And I want to add this “Archive”-Page into one of the Front Page Widget Areas.
First I thought of writing a Widget that pulls all the posts like this Archive-Page and insert that Widget in the designated Widget Area on Front Page.
How can I do this? Is there a way to include that Archive Portfolio Page?
That’s why I need to figure it out:
The Website will be a onepager, after a Slider(Front Page 1) this kind of Blogroll comes with the Portfolio-Items displayed in Masonry-Style like this tutorial (Front Page 2). Later there will be some functionality added like a “Load More” Button (to display more Portfolio-Items and stay on same Page (Onepage)). Another functionality will be an ordering function that allows the user to click a tag/category link under the Posts (where it says Filed under) and that section will only show the posts under this category (but still on same page because the Onepager).
You may want to give this a try: https://sridharkatakam.com/filterable-portfolio-grid-on-front-page-and-archive-page-in-altitude-pro-with-title-excerpt-and-clickable-custom-fields-on-hover/
Alternately take a look at https://wordpress.org/plugins/ajax-load-more/ and https://sridharkatakam.com/go/eg/
Thank you for an answer 🙂
I will have a look at these one’s, the ajax load more is perfect 😉
Is there a way to add this style here on to the get_posts results?
Because you just tell wordpress to take the archive-portfolio.php as theme here:
if ( is_tax( ‘portfolio_category’ ) || is_tax( ‘portfolio_tag’ ) )
$template = get_query_template( ‘archive-portfolio’ );
return $template;
Is there a way I can tell wordpress to use the template for get_posts? Like get_posts_template(‘archive-portfolio’)?
Thank you 🙂
Hello Sridhar,
Thanks for this very useful tutorial.
I don’t know why but my portfoio category loads the template index.php instead of the archive-portfolio template ?
See : http://goo.gl/nYqBzu
Have you any recommandation ?
Thank you
FYI Demo is dead but great tutorial!
Thanks. I have removed the dead link.