- This topic has 9 replies, 3 voices, and was last updated 3 years, 4 months ago by
David.
-
AuthorPosts
-
December 15, 2022 at 1:56 pm #2463420
Lars
Hi!
On https://bywildera.com/recipes/ I have a blog page with masonry layout. All is good and nice, but I notice that the masonry layout also affects the dynamic content in the footer (element). How can I stop that from happening?
Another question that concerns the masonry layout. Is there a way to write CSS for top posts and only the top three if three are shown, and only the top two if two are shown and only the top one is one is shown (mobile layout)?
December 15, 2022 at 6:00 pm #2463546Fernando Customer Support
Hi Lars,
1. Can you try adding this PHP snippet:
add_filter( 'post_class', function( $classes ) { if ( is_archive() && in_array( 'gb-query-loop-item', $classes ) ) { $index = array_search('generate-columns',$classes); if($index !== FALSE){ unset($classes[$index]); } } return $classes; } );Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
2. Can you try adding this snippet for this:
add_action( 'pre_get_posts', function( $query ) { if ( $query->is_main_query() && ! is_admin() && is_home() && wp_is_mobile() ) { $query->set( 'posts_per_page', 3 ); } } );Ideally, this sets the number of posts in your Blog to 3 on mobile.
Let us know how it goes.
December 16, 2022 at 12:37 am #2463732Lars
1. I have tried to insert this to Run Everywhere with the WPCode-plugin. The code is activated and should be doing whatever it is supposed to be doing. The footer still look like this on the blog page:
December 16, 2022 at 12:49 am #2463743Fernando Customer Support
I see. To test, can you try adding it through Code Snippets as shared in the article above? Let us know how it goes.
December 19, 2022 at 1:39 am #2466629Lars
I have now used Code Snippets instead and the result is the same: https://bywildera.com/recipes/
December 19, 2022 at 1:52 am #2466644Fernando Customer Support
I see. That’s odd.
Can you provide admin login credentials? We’ll take a closer look. Keep the code added through Code Snippets as well.
Please use the Private Information field for this: https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information
December 19, 2022 at 1:57 am #2466648Lars
Yeah, here’s the info:
December 19, 2022 at 5:13 pm #2467624Fernando Customer Support
Thank you.
Can you replace the code we have to remove the Query Loop columns with this?:
add_filter( 'post_class', function( $classes ) { if ( in_array( 'gb-query-loop-item', $classes ) ) { $index = array_search('generate-columns',$classes); if($index !== FALSE){ unset($classes[$index]); } } return $classes; } );Let us know how it goes.
December 20, 2022 at 3:28 am #2467958Lars
That did the trick and it also made me curious what you did here. Do you have the time to explain?
Thanks!
LarsDecember 20, 2022 at 5:44 am #2468081David
StaffCustomer SupportHi there,
the Javascript/CSS that is used for Masonry relies on the
generate-columnspost class which GP injects into all posts using thepost_classfilter hook.
However this also affects posts output in the query loop, which we need to address in an update.The code that Fernando provided uses the same filter to:
1. find posts with the post_class of
gb-query-loop-itemwhich exists on any GB Query Loop post.
2. check if the post_class also contains the problemgenerate-columns
3. if it does then remove that class. -
AuthorPosts
- You must be logged in to reply to this topic.