- This topic has 5 replies, 2 voices, and was last updated 7 years, 2 months ago by Tom.
-
AuthorPosts
-
January 25, 2017 at 2:05 pm #268695Diego Fernando
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
January 25, 2017 at 5:27 pm #268772TomLead DeveloperLead DeveloperTough 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 π
January 26, 2017 at 6:05 am #269051Diego FernandoHello 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
January 26, 2017 at 10:37 am #269218TomLead DeveloperLead DeveloperThis 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 ''; } }
January 27, 2017 at 9:18 am #269864Diego FernandoThanks a lot Tom. It work. π
January 27, 2017 at 10:28 am #269919TomLead DeveloperLead DeveloperYou’re welcome π
-
AuthorPosts
- You must be logged in to reply to this topic.