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.

add content (not excerpt) in a query loop block

  • Okay, according to this topic:
    https://generate.support/topic/query-loop-full-content-and-word-count/

    It is not possible to add the full content (not just the excerpt) into a query loop block. But I can’t believe there isn’t an easy solution to achieve this. Changing the excerpt length is not an option because I need to output a button (and maybe other blocks that are inside the content), and when you choose ‘excerpt’ it returns only plain text…

    How can I proceed? Maybe I will need to create a shortcode? But, if this has to be the option, can I create a shortcode from the elements section and call it? Or will I need to get my hands dirty and write code in the functions file, and then call the shortcode?

    BTW, I’m working on an static page that have other loops showing content from different CPTs, so this is not an archive page.

    Can you please guide me on how to achieve it? Thanks.

  • Hi there,

    the issue arises from WordPress restricting access to the core Post Content block. So what was an easy thing to do by virtue of the core blocks code, is now a bit of a pain.

    I can ‘t guarantee this will work but you could try this:

    1. Add this PHP Snippet to your site.
    It has to be a functions.php in your child theme or via a code snippets plugin

    
    add_filter( 'render_block', function( $block_content, $block ) {
        if (is_admin() || wp_is_json_request()) {
            return $block_content;
        }
    
        // variable to track the state and prevent infinite loops
        static $inside_loop = false;
    
        if ($inside_loop) {
            return $block_content;
        }
    
        if ( ! empty( $block['attrs']['className'] ) && 'show-post-content' ===  $block['attrs']['className'] ) {
            global $post;
    
            $inside_loop = true;
            $post_content = apply_filters('the_content', $post->post_content);
            $inside_loop = false;
    
            return $post_content;
        }
    
        return $block_content;
    }, 10, 2 );
    

    2. add a Headline block as a placeholder in your loop, and give the headline an Advanced > Additional CSS Class of: show-post-content.
    Which is the class we specify in the snippet.

    On the front end this “should” render the post content in full.

  • Okay! It’s almost perfect!
    Why is it not returning any style given (in the backend) to the headline placeholder block?
    Ideally, I want to assign some style from the backend to this headline block, i.e., font size and line height, maybe color… Is it possible?
    I guess that with this code you are replacing the whole content that the block contains, but maybe there is a way to keep the style declared in the frontend?

  • The most you could do is to place the headline inside a container block.
    And on the container block set the font styles and perhaps color for the text

    If the post content is inheriting its font size and color from the body ( which is the default behaviour for the GP theme ) it would not inherit them from that container block.

  • Okay, thank you. I hope you can integrate this functionality into the core GP and GB.
    As always, the experience with your support service is wonderful. I’m happy to trust in GP!

  • You’re welcome

  • Thanks

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