- This topic has 13 replies, 2 voices, and was last updated 4 years ago by Tom.
-
AuthorPosts
-
March 25, 2020 at 3:04 am #1209281reistad
I have made a child theme and added a category.php which is a copy of archive.php from the mother theme and a content-category.
Then altered the content-category so it show excerts. But how do I include a read more text after the excert.
March 25, 2020 at 9:52 am #1209842TomLead DeveloperLead DeveloperHi there,
Are you only trying to set excerpts in a specific category?
If so, you could do this instead of creating a custom page template:
add_filter( 'generate_show_excerpt', function( $show ) { if ( is_category( 'Your Category Name' ) ) { return true; } return $show; } );
As for the category page and sub-categories, this might help: https://wordpress.stackexchange.com/a/136490/90661
April 1, 2020 at 1:34 am #1221792reistadI removed the category.php and tried your solution . But it did’nt work
I am using the manual excerpt field in the blog post.
I want the excerpts to show on category pages with a read more link.
In ‘Customizer > Layout > Blog> Archives Content Type> Excerpt I have “Display read more as button” and has “Read more label” set to ‘Read full article’
But the Read More button does not show after the excerpt on category pages.
Is there a problem since I am using manual excerpts?
April 1, 2020 at 10:20 am #1222446TomLead DeveloperLead DeveloperYes, you can add the read more button to manual excerpts like this: https://docs.generatepress.com/article/activating-read-custom-excerpt/
April 1, 2020 at 12:37 pm #1222636reistadAdded this to the end of functions.php
/* My own */
add_filter( ‘wp_trim_excerpt’, ‘tu_excerpt_metabox_more’ );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;if ( has_excerpt() ) {
$output = sprintf( ‘%1$s <p class=”read-more-button-container”>%3$s</p>’,
$excerpt,
get_permalink(),
__( ‘Read more’, ‘generatepress’ )
);
}return $output;
}But did not help. Is it because I have written manual excerpts for the posts?
Read more buttons only appear for the posts without manual excerpts.
April 1, 2020 at 4:31 pm #1222847TomLead DeveloperLead DeveloperHmm, instead of
wp_trim_excerpt
, can you tryget_the_excerpt
?April 2, 2020 at 12:42 am #1223017reistadTried it, but did not work.
Is there a way to show whether “has_excerpt()” is false when you have a custom excerpt, just now in the development stage for the site.April 2, 2020 at 8:49 am #1223760TomLead DeveloperLead DeveloperYou could try putting
var_dump('hi');
inside thehas_excerpt()
conditional to see if it’s firing at all.April 2, 2020 at 1:01 pm #1224075reistadInluded it as follows:
———————————
add_filter( ‘wp_trim_excerpt’, ‘tu_excerpt_metabox_more’ );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;if ( has_excerpt() ) {
var_dump(‘hi’);
$output = sprintf( ‘%1$s <p class=”read-more-button-container”>%3$s</p>’,
$excerpt,
get_permalink(),
__( ‘Read more’, ‘generatepress’ )
);
}return $output;
}
—————————————No “hi” as result in the category: Our Activities or other categories.
https://www.dropbox.com/s/txdb01w7jk7i3xq/Skjermbilde%202020-04-02%2021.54.56.png?dl=0
April 2, 2020 at 5:02 pm #1224247TomLead DeveloperLead DeveloperIs there any way you can link me to the site so I can inspect the code?
Any var_dump using
get_the_excerpt
instead ofwp_trim_excerpt
?April 3, 2020 at 1:01 am #1224491reistadNO success with “get_the_excerpt”.
Sent you login for ftp and login for the Wp-site on Messenger GeneratePress.com.
April 3, 2020 at 10:47 am #1225370TomLead DeveloperLead DeveloperI just tried this function:
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' ); function tu_excerpt_metabox_more( $excerpt ) { $output = $excerpt; if ( has_excerpt() ) { $output = sprintf( '%1$s <p class="read-more-button-container"><a class="button" href="%2$s">%3$s</a></p>', $excerpt, get_permalink(), __( 'Read more', 'generatepress' ) ); } return $output; }
I added a custom excerpt here: https://www.screencast.com/t/s0fAfjrbPf
And here’s the result: https://www.screencast.com/t/abOlcDht6fY
If that’s not working on your end, you may have a conflicting plugin/function.
April 3, 2020 at 12:10 pm #1225478reistadHello Tom. I deleted the theme folder and copied over a fresh one and included your filter.
Now everything works perfect.
Sorry to trouble you so much.
I must have done something wrong with the files when I was fiddling with the files to make special category pages.I have now understood that it is far better to use filters and hooks.
I will make an effort to learn more about filters and hooks and how to use it in GeneratePress.
So thanks again for grate support!
April 3, 2020 at 5:04 pm #1225690TomLead DeveloperLead DeveloperNo trouble! Glad I could help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.