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.

Need full text of post in one query loop only

  • Can’t find a Full Post Content block option for the query loop – there is nothing like this in the block choices, and every other post on the site requires an excerpt. (so can’t change the choice in the customizer or it will screw up every other loop)

    How to do this? Site: https://avenueroadsafetycoalition.ca – the first section of the page is currently just plain old text & photos – but since some of the time those bits need to later migrate down into the news section, I’d like to make them posts instead. Can’t figure out how to make them show the full post content while they’re in the “main” (single post on the home page) category. I tried – had to take it out. Time constraints – client needed this to go up now.

  • 1. Try this PHP snippet:

    add_filter( 'render_block_generateblocks/headline', function( $block_content, $block ) {
        if ( ! is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'full-content' ) !== false ) {
            global $post;
            $post_id = get_the_ID();
            $post = get_post( $post_id );
            $post_content = $post->post_content;
            
            // Remove HTML comments from the post content
            $sanitized_content = preg_replace( '/<!--(.|\s)*?-->/', '', $post_content );
            
            $block_content = '<div class="full-post-content">' . $sanitized_content . '</div>';  
            return $block_content;	
         }
    }, 10, 2 );
    

    2. Add the class full-content to the headline block, disable its dynamic data.
    Adding CSS class(es): https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

  • Well, I’m afraid that doesn’t work. See: https://avenueroadsafetycoalition.ca/testing-2/

    I added the PHP snippet (to Snippets plugin), enabled it, added the Query Loop block to the page, and then added the class full-content to the Excerpt headline block (tried it in both CSS and block name, in case that was where I was supposed to put it), but the moment I turned off dynamic data, it switches to “Headline” (in edit view) with nothing there. I’m definitely missing something here…

  • How did you add the PHP snippet?

  • As I noted…to the Snippets plugin. But I just went in and looked and the snippet itself wasn’t enabled (I truly thought I’d done it, but apparently not) – and that was the problem. Id-10-t error. 😉

    It’s working now! Thank you.

  • Glad to hear that :)

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