Archived topic
Set excerpt only for categories
5 replies · Started by Diego Fernando on January 25, 2017
Hello Tom
Please, two questions
How can I set the excerpt but only for the categories. On the home page, if is possible, I just want excerpt only for the first post that has full width. The rest of the post, I don't want to have excerpt.
The second question is:
On home page (blog page), when I place the empty excerpt field, I get 3 dots (...) below the featured image. How can I delete them? I was viewing related post, but were about to delete dots with masonry style. I have columns.
Thank you for your help. I love GP
Tough question! You would use the excerpt_length filter.
For example, this will set the excerpt length of the first post on a page, then the rest won't have an excerpt:
add_filter( 'excerpt_length','tu_custom_excerpt_length', 1000 );
function tu_custom_excerpt_length( $length ) {
global $wp_query; // assuming you are using the main query
if ( 0 === $wp_query->current_post) {
return $length;
} else {
return 0;
}
}
You can add more conditionals in there for is_category() etc..
Then you can do the same thing for the more link:
add_filter( 'excerpt_more', 'tu_custom_more_tag', 100 );
function tu_custom_more_tag( $more ) {
global $wp_query; // assuming you are using the main query
if ( 0 === $wp_query->current_post) {
return $more;
} else {
return '';
}
}
Hope that's enough to get you going :)
Hello Tom
Maybe, there is a mistake in my procediment
I put the code in Simple PHP. I got an excerpt in the the first post of home and categories page, and the rest of the post don't have excerpt. It is wonderfur for the home page.
But I was wondering, how I can set normal excerpt in categories? I want all posts with excerpt.
Tom, thank you for the support
This should do it:
add_filter( 'excerpt_length','tu_custom_excerpt_length', 1000 );
function tu_custom_excerpt_length( $length )
{
// Return the normal length if we're not on the front page
if ( ! is_front_page() )
return $length;
global $wp_query; // assuming you are using the main query
if ( 0 === $wp_query->current_post) {
return $length;
} else {
return 0;
}
}
add_filter( 'excerpt_more', 'tu_custom_more_tag', 100 );
function tu_custom_more_tag( $more )
{
// Return the normal more link if we're not on the front page
if ( ! is_front_page() )
return $more;
global $wp_query; // assuming you are using the main query
if ( 0 === $wp_query->current_post) {
return $more;
} else {
return '';
}
}
Thanks a lot Tom. It work. :D
You're welcome :)