[Resolved] Category page with excerpts with read more

Home Forums Support [Resolved] Category page with excerpts with read more

Home Forums Support Category page with excerpts with read more

  • This topic has 13 replies, 2 voices, and was last updated 4 years ago by Tom.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1209281
    reistad

    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.

    #1209842
    Tom
    Lead Developer
    Lead Developer

    Hi 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

    #1221792
    reistad

    I 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?

    #1222446
    Tom
    Lead Developer
    Lead Developer

    Yes, you can add the read more button to manual excerpts like this: https://docs.generatepress.com/article/activating-read-custom-excerpt/

    #1222636
    reistad

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

    #1222847
    Tom
    Lead Developer
    Lead Developer

    Hmm, instead of wp_trim_excerpt, can you try get_the_excerpt?

    #1223017
    reistad

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

    #1223760
    Tom
    Lead Developer
    Lead Developer

    You could try putting var_dump('hi'); inside the has_excerpt() conditional to see if it’s firing at all.

    #1224075
    reistad

    Inluded 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

    #1224247
    Tom
    Lead Developer
    Lead Developer

    Is there any way you can link me to the site so I can inspect the code?

    Any var_dump using get_the_excerpt instead of wp_trim_excerpt?

    #1224491
    reistad

    NO success with “get_the_excerpt”.

    Sent you login for ftp and login for the Wp-site on Messenger GeneratePress.com.

    #1225370
    Tom
    Lead Developer
    Lead Developer

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

    #1225478
    reistad

    Hello 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!

    #1225690
    Tom
    Lead Developer
    Lead Developer

    No trouble! Glad I could help 🙂

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.