- This topic has 17 replies, 3 voices, and was last updated 1 week, 1 day ago by
David.
-
AuthorPosts
-
January 17, 2023 at 4:56 pm #2499518
Chad Biggs
I created some custom fields using ACF Pro and placed the code in my child theme’s single.php page. I need to display excerpts of the custom fields from the single.php to the archives page. I think the normal way to do this is to change php the_content to php the_excerpt on the archives page and add some code to the functions page but the_content is not on the GP archives page. How can I add excerpts to the archives page from ACF single.php? Thank you.
January 17, 2023 at 5:26 pm #2499530Fernando Customer Support
Hi Chad,
To clarify, is the excerpt you want to add to the archive pages a custom field from ACF?
If so, might I suggest using a Block Element – Content Template for the archive page, and then adding this custom field through a GB Headline Block’s dynamic setting if possible? Reference: https://docs.generatepress.com/article/block-element-content-template/
In this way, you wouldn’t need to alter template files.
Another way is to simply hook the field to articles on the archive page.
I would personally use a Content Template because it’s much easier to control.
January 19, 2023 at 6:20 am #2501438Chad Biggs
With the blocks, I can pull in the Post title, author and date but I cant get the excerpt text to populate. Is there a way to target a specific class using the blocks? Or is there a line I can add to my single.php page?
January 19, 2023 at 8:18 am #2501742David
StaffCustomer SupportHi there,
in the Headline Blocks Dynamic Data options you can set the Content Source to
Post Meta
and add the ACF Fieldname in the field provided.
NOTE: it won’t work with repeater fields.But …. does the ACF fields content need trimming to an excerpt ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 19, 2023 at 12:15 pm #2502044Chad Biggs
I have dynamic data set to post meta and the field name is entered. It all looks right to me compared to what I read from you but it’s still not working. The field I am trying to get is a text field, not a repeater.
January 19, 2023 at 7:00 pm #2502250Fernando Customer Support
Hi Chad,
From your screenshot, I can see that you’re not using a GB Headline Block.
Here’s an example of how to do it: https://share.getcloudapp.com/WnuZpJGr
Reference: https://docs.generateblocks.com/article/headline-overview/#dynamic-data
With that said, can you try retrieving it through a GB Headline Block?
January 20, 2023 at 10:30 am #2503256Chad Biggs
Thank you. Is there a way to limit the characters to 55-60 in the excerpt?
January 20, 2023 at 11:24 am #2503336David
StaffCustomer SupportIf you’re display the post Excerpt in the Headlines Dynamic data, then there is an option to change its length.
Check the front end if you don’t see a change in the editorIf you want to trim the length of the custom field, then you would need to do that using a shortcode. See here:
https://support.advancedcustomfields.com/forums/topic/trimming-words-from-a-field/#post-149508
Then the shortcode can be added inside a Headline Block
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 22, 2023 at 8:29 pm #2505317Chad Biggs
I do not see an option to change the excerpt length under the dynamic headline in the elements. I have attached a snapshot of my list view group layout in case I am doing something wrong.
By “Check the front end if you don’t see a change in the editor”, I guess you mean I can set the excerpt length in customizing/layout/blog/ content type. But changing any settings under content type does not make any changes.
January 22, 2023 at 10:14 pm #2505369Fernando Customer Support
Hi Chad,
Try adding
trim-custom-description
to the class list of the Headline Block.Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
Then, add this snippet:
add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){ if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'trim-custom-description' ) !== false ) { $content = wp_trim_words( $content, 2, '...' ); } return $content; }, 10, 3);
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Change
2 in wp_trim_words( $excerpt, 2, '...' )
to the preferred excerpt length.January 23, 2023 at 6:02 am #2505766Chad Biggs
Thank you for your help!
January 23, 2023 at 5:01 pm #2506550Fernando Customer Support
You’re welcome, Chad!
January 24, 2023 at 6:41 am #2507117Chad Biggs
Do you know if there is a way to change that code to limit characters instead of words?
January 24, 2023 at 7:00 am #2507136David
StaffCustomer SupportHi there,
try changing this:
$content = wp_trim_words( $content, 2, '...' );
to:
$stripHTML = strip_tags($content); $content = substr($stripHTML, 0, 15);
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 24, 2023 at 8:05 am #2507389Chad Biggs
That works great but I have tried every scenario I can think of to get the ‘…’ behind the last word like the other code had. It is possible?
-
AuthorPosts
- You must be logged in to reply to this topic.