- This topic has 9 replies, 2 voices, and was last updated 6 years ago by
Tom.
-
AuthorPosts
-
November 8, 2017 at 4:06 pm #418936
wekhter
First off, I’m loving all the new options for archive layouts in the latest GP update. I’m especially glad to see an option to use masonry + pagination instead of only endless scrolling! There’s just one issue, though: I had been using the following code to make it so that I could use masonry on the blog archive, and columns on my CPT archives.
// Disable masonry on animation CPT add_filter( 'generate_blog_masonry','generate_adjust_masonry' ); function generate_adjust_masonry( $masonry ) { if ( !is_woocommerce() && ( is_post_type_archive() || is_tax() ) ) : return 'false'; endif; return $masonry; } // Enable columns on animation CPT add_filter( 'generate_blog_columns','generate_adjust_columns' ); function generate_adjust_columns( $columns ) { if ( !is_woocommerce() && ( is_post_type_archive() || is_tax() ) ) : return true; endif; return $columns; }
With the new changes to columns/masonry, this no longer works and my CPT uses the same settings as the blog.
I need the blog to be 2 column masonry + first post featured, and the CPT to be 4 column non-masonry + first post not featured. How do I get that working again?
November 8, 2017 at 4:17 pm #418949Tom
Lead DeveloperLead DeveloperHi there,
Glad you like the update! Sorry about this, I tried to make everything as backward compatible as possible.
First, set your blog settings in the Customizer to what you want everywhere.
Then do this to disable masonry on your custom post type:
add_filter( 'generate_blog_masonry', 'tu_adjust_masonry' ); function tu_adjust_masonry( $masonry ) { if ( ! is_woocommerce() && ( is_post_type_archive() || is_tax() ) ) { return 'false'; } return $masonry; }
As for the featured post, nothing in your code above would have affected that. But you can turn it off like this:
add_filter( 'option_generate_blog_settings', 'tu_adjust_featured_image' ); function tu_adjust_featured_image( $options ) { if ( ! is_woocommerce() && ( is_post_type_archive() || is_tax() ) ) { $options['featured_column'] = false; } return $options; }
Let me know if this helps or not π
November 8, 2017 at 5:21 pm #419005wekhter
@Tom Almost there! I’ve disabled masonry on my CPT now, but how can I set up the number of columns? I need 2 columns in my blog and 4 columns on this CPT.
Just as a request–it would be great to be able to set this sort of thing up in the options, just like how you’ve added options for archive vs single… post archive, single post, cpt archive, cpt? Archive styling for blogs doesn’t necessarily work for other things, like portfolio archives (as an example). It could be a very helpful addon, similar to the woocommerce addon.
November 8, 2017 at 5:23 pm #419006Tom
Lead DeveloperLead DeveloperThis should help for setting the number of columns: https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns
It’s hard to add options for this, as there can be an infinite number of CPTs on a site. That’s what filters are for π
November 8, 2017 at 5:47 pm #419020wekhter
@Tom Getting closer in that I can set the columns to the correct width I want, but it seems that once I enable columns masonry is automatically applied as well, whether or not I have the snippet that sets masonry to false, so even though the blocks are 25% width, they’re absolute positioned into 2 columns from the masonry script.
And gotcha, I figured it was a long shot request π
November 8, 2017 at 5:54 pm #419023Tom
Lead DeveloperLead DeveloperCan you link me to that page possibly?
November 8, 2017 at 6:12 pm #419036wekhter
@tom Here you go: http://unsightly-gerbil.w3.poopy.life/animation/ It’s my test site so don’t mind the general mess. As you can see, I’ve set it to be 25% width columns, but the masonry script is taking over placement.
November 8, 2017 at 6:45 pm #419050Tom
Lead DeveloperLead DeveloperLet’s do it a little differently.
Turn masonry off in the Customizer.
Then do this:
add_filter( 'generate_blog_masonry', 'tu_adjust_masonry' ); function tu_adjust_masonry( $masonry ) { if ( is_home() ) { return 'true'; } return $masonry; }
November 9, 2017 at 7:33 am #419627wekhter
@Tom All working perfectly now, thanks!
November 9, 2017 at 7:36 am #419630Tom
Lead DeveloperLead DeveloperYou’re welcome π
-
AuthorPosts
- You must be logged in to reply to this topic.