Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

How to add the category description in the first block of a custom posts grid ?

  • Hi,
    I use a generate press element to build my custom post grid with the query loop block of generate blocks pro. I created another generate press element for a dynamic block that will display the category name and description. I would like to add this description block in the query loop block of the other gp element. How can I do this please ?

    Thank you for your feedback,

    Sincerely

    Nicolas

  • Hi there,

    I would like to add this description block in the query loop block of the other gp element.

    Are you trying to add the description block into the query loop block? If so, no, you can not do that, it will break the query loop block’s structure.

    Do you want the description block as the 1st post in your loop? Is the query block used as a loop template, or it a query block in a static page?

    Can you explain some more? Or can i see it on your site?

    Let me know 🙂

  • Hi Ying and thanks for your help,

    Yes, i want the description as the first post in my loop. I use the query loop block in an element of generate press and display it in the category template of my custom posts.

    Best regards,

    Nicolas

  • I see; try this:

    1. Add the class my-looper to the Grid block of the query.
    Adding CSS class(es): https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

    2. Add this PHP code to create a custom hook queryloop_insert_hook_1.

    add_filter( 'render_block', function( $block_content, $block ) {
        global $loopnumber;
    
        if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'my-looper' ) !== false ) {
            ob_start();
            do_action('queryloop_insert_hook_'.($loopnumber+1));
            $insertblock = ob_get_clean();
    		
            if($insertblock) {
                $block_content = '<div class="gb-grid-column gb-query-loop-item">'.$insertblock.'</div>'.$block_content;
            }
            $loopnumber++;
        }
        return $block_content;
    }, 10, 2 );

    3. You can create a block element – hook, add your content, and set the hook to custom hook > queryloop_insert_hook_1.

  • Great, it works fine. Thank you a lot Ying ! Have a nice day 😉

  • You are welcome   🙂

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