Site logo

[Support request] Dynamic Data settings not working for headline block

Home Forums Support [Support request] Dynamic Data settings not working for headline block

Home Forums Support Dynamic Data settings not working for headline block

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2579197
    Trey

    I am using GeneratePress Elements Loop Template to display the blogs posts on my blog page. It is using the headline dynamic data to display the post exerpt and “read more” link. However, the dynamic data settings are only being applied to the last post in the loop. The Exerpt length setting and “Read more” link only apply to the last post in the query loop. I would like the dynamic data settings to apply for all posts in the query loop.

    #2579229
    Ying
    Staff
    Customer Support
    #2579325
    Trey

    Hi Ying,

    The solution in the article worked to get the “read more” link to show up. It looks like my custom excerpts were the issue. However, I also need to have the excerpts truncated according to the word count setting in dynamic data. Is there a solution for that?

    Thanks

    #2579531
    Ying
    Staff
    Customer Support

    However, I also need to have the excerpts truncated according to the word count setting in dynamic data

    Try this method:

    1. Add an additional CSS class to the headline block which represents the excerpt, eg. custom-excerpt.
    https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

    2. Add the below PHP code, change the 10 of $custom_excerpt, 10, '...' to the word count you want to apply:

    add_filter( 'render_block', function( $block_content, $block ) {
    	if ( ! empty( $block['attrs']['className'] ) && 'custom-excerpt' ===  $block['attrs']['className'] ) {
    		$custom_excerpt = get_the_excerpt();
    		$limited_excerpt = wp_trim_words( $custom_excerpt, 10, '...' );
    		$block_content = sprintf( '%1$s <a href="%2$s">%3$s</a>',
    			$limited_excerpt,
    			get_permalink(),
    			__( 'Read more', 'generatepress' )
    		);
    	}
    	
    	return $block_content;
    }, 10, 2 );
    

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #2579621
    Trey

    Hi Ying,

    Thanks for the code. I have implemented it and it works, however, the formatting that I used for the excerpt’s headline block is not working anymore. Specifically, the font size, line spacing, and top border and border color are not working.

    Please let me know if you have a solution

    Thanks

    #2579755
    Fernando
    Customer Support
    #2580962
    Trey

    Hi Fernando,

    Your solution worked to truncate the excerpt text. But now the grid is not stacking properly and the “Read more…” text link after the excerpt is gone. Also, some of the formatting in the sidebar is now not working – some of the text has changed color like its a link, and one of the social icons is a weird shape? Seems like a weird side-effect

    #2581090
    Ying
    Staff
    Customer Support

    Can you try this:

    1. Remove the codes from me and Fernando.

    2. Disable the dynamic data option completely for the headline block.

    3. Add static text content, eg. my-custom-excerpt, screenshot below for your reference:
    https://www.screencast.com/t/xY7wHydiN4

    4. Add this code, change the 10 of $custom_excerpt, 10, '...' to the word count you want.

    add_filter( 'render_block', function( $block_content, $block ) {
        if (  ! empty( $block['attrs']['className'] ) && 'custom-excerpt' ===  $block['attrs']['className'] )  {
         
    	$custom_excerpt = get_the_excerpt();
            $limited_excerpt = wp_trim_words( $custom_excerpt, 10, '...' );
    		
            $new_content = sprintf( '%1$s <a href="%2$s">%3$s</a>',
            $limited_excerpt,
            get_permalink(),
                __( 'Read more', 'generatepress' )
            );
    		
    	$block_content= str_replace('my-custom-excerpt',$new_content,$block_content );
        }
    
        return $block_content;
    }, 10, 2 );

    Let me know how it goes this time!

    #2581282
    Trey

    Hi Ying,

    Your code worked!

    Really appreciate you and Fernando’s help on this one

    Thanks!

    #2583299
    Fernando
    Customer Support

    You’re welcome, Trey!

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