[Resolved] Set excerpt only for categories

Home Forums Support [Resolved] Set excerpt only for categories

Home Forums Support Set excerpt only for categories

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #268695
    Diego 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

    #268772
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #269051
    Diego Fernando

    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

    #269218
    Tom
    Lead Developer
    Lead Developer

    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 '';
        }
    }
    #269864
    Diego Fernando

    Thanks a lot Tom. It work. πŸ˜€

    #269919
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

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