Site logo

[Support request] Masonry Layout on blog changes content in footer

Home Forums Support [Support request] Masonry Layout on blog changes content in footer

Home Forums Support Masonry Layout on blog changes content in footer

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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)?

    #2463546
    Fernando
    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.

    #2463732
    Lars

    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:

    #2463743
    Fernando
    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.

    #2466629
    Lars

    I have now used Code Snippets instead and the result is the same: https://bywildera.com/recipes/

    #2466644
    Fernando
    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

    #2466648
    Lars

    Yeah, here’s the info:

    #2467624
    Fernando
    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.

    #2467958
    Lars

    That did the trick and it also made me curious what you did here. Do you have the time to explain?

    Thanks!
    Lars

    #2468081
    David
    Staff
    Customer Support

    Hi there,

    the Javascript/CSS that is used for Masonry relies on the generate-columns post class which GP injects into all posts using the post_class filter 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-item which exists on any GB Query Loop post.
    2. check if the post_class also contains the problem generate-columns
    3. if it does then remove that class.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.