Site logo

Archived topic

Posts excerpts

25 replies · Started by John on February 28, 2023

Viewing posts 16–26 of 26

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 of anecdotes-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/

Thanks, Dave.

I just added it as a Snippet.
However, I see no change.

Could it be because I'm running a child theme?

Ok, 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 the anecdotes-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.

Gladly, 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.

On 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.

OK, 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' );

Hi 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

Glad to hear that!

Thanks, Dave.

John

This archived topic is closed to new replies.