- This topic has 25 replies, 4 voices, and was last updated 1 year, 4 months ago by John.
-
AuthorPosts
-
April 13, 2023 at 6:04 am #2608394DavidStaffCustomer Support
Ok, so this PHP Snippet:
function db_show_excerpt_child_term( $show_excerpt ) { $parent_term = get_term_by('slug', 'anecdotes-list', 'category'); if (is_category() && $parent_term && get_queried_object()->parent == $parent_term->term_id) { return true; } return $show_excerpt; } add_filter( 'generate_show_excerpt','db_show_excerpt_child_term' );
It will:
1, get our
$parent_term
that has the slug ofanecdotes-list
2. check if the current archive term is a child of the parent.
3. is yes it will tell GP to shown the excerpt.HOW to add PHP: https://docs.generatepress.com/article/adding-php/
April 13, 2023 at 6:28 am #2608415JohnThanks, Dave.
I just added it as a Snippet.
However, I see no change.Could it be because I’m running a child theme?
April 13, 2023 at 6:49 am #2608429DavidStaffCustomer SupportOk, it is working but my understanding of whats required obviously is obviously not lol
See here:
https://understand-culture.com/category/anecdotes-list/agreements-anecdotes/
The
agreements-anecdotes
is an archive page that is a child term of theanecdotes-list
And its showing an excerpt now. which is what that code does.So lets start over 🙂
Can you show me the page where you want to see a list of all Anecdotes that show just the excerpt.April 13, 2023 at 6:56 am #2608438JohnGladly, Dave.
Please go to:
https://understand-culture.com/anecdotes/Click on my last name – Magee – under authors.
Or simply pick any of the topics.I have the respective anecdotes groups by
topic (category), and by author. Currently,
I’m the only author.April 13, 2023 at 7:17 am #2608456DavidStaffCustomer SupportOK…. so this is where things get tricky.
If i choose the topic of
Agreements
then it opens the child term archive i shared above ie.https://understand-culture.com/category/anecdotes-list/agreements-anecdotes/
And that shows the excerpt. Is that correct?
Then we can discuss the tricky part…..
April 13, 2023 at 7:36 am #2608467JohnOn my side I see that the post “Strange Black Man”
has been successfully excerpted.But if you access anecdote-posts from other entry
points – i.e. Magee or via a topic – I see that some
anecdote-posts are excerpted, while others are not.April 14, 2023 at 2:57 am #2609420DavidStaffCustomer SupportOK, after some head scratching, this may do what you require.
What it should do on any category archive, if a post has a category term that includes the string:
anecdotes
it will set that post to display the excerpt.function db_show_excerpt_child_term( $show_excerpt ) { $terms = get_the_terms( $post->ID, 'category' ); if ( is_category() && $terms && ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { if ( strpos( $term->slug, 'anecdotes' ) !== false ) { return true; } } } return $show_excerpt; } add_filter( 'generate_show_excerpt','db_show_excerpt_child_term' );
April 14, 2023 at 9:05 am #2609899JohnHi Dave,
It works great if and when you choose a topic.
However, if you choose “Magee” or “Germany” or
“USA” then no excerpts. Crazy.Is that the case when you test?
John
April 15, 2023 at 3:34 am #2610443JohnWe got this solved, Dave.
Go to:
https://understand-culture.com/anecdotes/Pick any topic or Germany or USA.
All anecdotes are excerpted.Great work !
John
April 15, 2023 at 4:03 am #2610473DavidStaffCustomer SupportGlad to hear that!
April 15, 2023 at 4:44 am #2610494JohnThanks, Dave.
John
-
AuthorPosts
- You must be logged in to reply to this topic.