Site logo

Archived topic

Category page with excerpts with read more

13 replies · Started by reistad on March 25, 2020

Viewing posts 1–14 of 14

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.

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

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?

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.

Hmm, instead of wp_trim_excerpt, can you try get_the_excerpt?

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.

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

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

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?

NO success with "get_the_excerpt".

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

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.

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!

No trouble! Glad I could help :)

This archived topic is closed to new replies.