- This topic has 9 replies, 3 voices, and was last updated 2 years, 11 months ago by
Fernando.
-
AuthorPosts
-
March 23, 2023 at 11:05 am #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.
March 23, 2023 at 11:32 am #2579229Ying
StaffCustomer SupportHi Trey,
Can you check this article?
https://docs.generatepress.com/article/excerpt-issues/#read-more-label-or-button-not-showingMarch 23, 2023 at 12:42 pm #2579325Trey
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
March 23, 2023 at 5:00 pm #2579531Ying
StaffCustomer SupportHowever, 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
10of$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/
March 23, 2023 at 7:14 pm #2579621Trey
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
March 23, 2023 at 10:49 pm #2579755Fernando Customer Support
Hi Trey,
Can you try this one insteaed?: https://generatepress.com/forums/topic/how-can-i-achieve-masonry-on-my-blog-page/#post-2533760
March 24, 2023 at 1:54 pm #2580962Trey
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
March 24, 2023 at 5:02 pm #2581090Ying
StaffCustomer SupportCan 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/xY7wHydiN44. Add this code, change the
10of$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!
March 25, 2023 at 12:17 am #2581282Trey
Hi Ying,
Your code worked!
Really appreciate you and Fernando’s help on this one
Thanks!
March 26, 2023 at 5:09 pm #2583299Fernando Customer Support
You’re welcome, Trey!
-
AuthorPosts
- You must be logged in to reply to this topic.