[Support request] Custom excerpt length on featured post

Home Forums Support [Support request] Custom excerpt length on featured post

Home Forums Support Custom excerpt length on featured post

  • This topic has 11 replies, 4 voices, and was last updated 1 year ago by Fernando.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1970518
    Karel

    Hi,

    I would like to change the excerpt length on the featured post only.
    I tried the solution given here https://generatepress.com/forums/topic/longer-excerpt-on-featured-post/ but on my site it doesn’t seem to work.

    It could be that I’m doing something wrong since another code snippet from this topic https://generatepress.com/forums/topic/blog-add-on-different-number-of-post-in-first-page-of-blog/ is also not working on my site.

    Thanks

    #1970543
    David
    Staff
    Customer Support

    Hi there,

    How are the Excerpts being created ? Are they a manual excerpt or is some other function generating them. As when i check the single post i cannot see that text in the content.

    #1970566
    Karel

    Hi David,

    These are normal automatic excerpts, not manual.
    Not sure what you mean when you say you don’t see the text in the content, the excerpt is exactly the same as the first words of the post content and was generated automatically.

    The post was made sticky to make it the first post in the blog
    In the customizer, the option “make first post featured” was turned on

    Thanks for looking into it

    #1970597
    David
    Staff
    Customer Support

    Sorry my bad … i am not sure what i was looking at 🙂

    I done a quick test with a Sticky Post, the filter to change the number of posts on the first page, and the Excerpt length filter and it worked.

    This is how my two functions look:

    add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
    function tu_change_posts_per_page( &$query ) {
        if ( ! is_main_query() ) {
            return;
        }
    
        if ( ! $query->is_paged ) {
            $query->set( 'posts_per_page', 15 ); // First page 15 posts
        }
    }
    
    add_filter( 'excerpt_length', 'tu_featured_excerpt_length', 50 );
    function tu_featured_excerpt_length( $length ) {
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        global $wp_query;
    
        if ( 1 == $paged && 0 == $wp_query->current_post ) {
            return 100; // First post
        }
    
        return $length;
    }
    #1970602
    Karel

    Thanks.
    Can’t get it to work unfortunately.
    I added your snippet in the extra CSS, but it has no effect, not the excerpt length and not on the nr of posts.
    (Other modifications in the extra CSS do work)

    Not sure what I’m doing wrong…

    #1970632
    David
    Staff
    Customer Support

    Aah… the code is PHP – this article explains how to add the code:

    https://docs.generatepress.com/article/adding-php/

    NOTE: If make sure you only add the functions once.
    So if this code is working for changing the number of posts displayed:
    https://generatepress.com/forums/topic/blog-add-on-different-number-of-post-in-first-page-of-blog/

    Then ONLY add the PHP provided here:
    https://generatepress.com/forums/topic/longer-excerpt-on-featured-post/

    #1970687
    Karel

    Ah, of course…Sorry.

    Both snippets work perfectly.
    Thank you very much!

    #1970705
    David
    Staff
    Customer Support

    Really glad to hear that!

    #2573387
    Oliver

    Hey guys, this answer helped me with half my problem… the other half is this: how would I go about making the title of the featured post bigger than the rest?

    #2573459
    Fernando
    Customer Support

    Hi Oliver,

    Can you open a new topic with regard to the other issue?

    #2573748
    Oliver

    No problem. Here is the Link in case someone who´s interested lands in here

    #2573753
    Fernando
    Customer Support

    Thank you, Oliver! Let’s continue in the new thread.

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