[Resolved] Posts excerpts

Home Forums Support [Resolved] Posts excerpts

Home Forums Support Posts excerpts

  • This topic has 25 replies, 4 voices, and was last updated 1 year ago by John.
Viewing 11 posts - 16 through 26 (of 26 total)
  • Author
    Posts
  • #2608394
    David
    Staff
    Customer 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 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/

    #2608415
    John

    Thanks, Dave.

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

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

    #2608429
    David
    Staff
    Customer Support

    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.

    #2608438
    John

    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.

    #2608456
    David
    Staff
    Customer Support

    OK…. 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…..

    #2608467
    John

    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.

    #2609420
    David
    Staff
    Customer Support

    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' );
    #2609899
    John

    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

    #2610443
    John

    We 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

    #2610473
    David
    Staff
    Customer Support

    Glad to hear that!

    #2610494
    John

    Thanks, Dave.

    John

Viewing 11 posts - 16 through 26 (of 26 total)
  • You must be logged in to reply to this topic.