[Resolved] Only show post as "Featured post" on homepage

Home Forums Support [Resolved] Only show post as "Featured post" on homepage

Home Forums Support Only show post as "Featured post" on homepage

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #680039
    Leon

    On the homepage I want to show the newest post as “featured post”. That works well, but now the newest post in the search and category pages are also “featured posts”. As it doesn’t make any sense there, I’d like to exclude those pages. I can’t find any solution so far.

    Thanks,
    Leon

    #680362
    Leo
    Staff
    Customer Support

    Hi there,

    You can use the option_generate_blog_settings filter.

    The code should be this:

    add_filter( 'option_generate_blog_settings', 'lh_disable_featured_column' );
    function lh_disable_featured_column( $options ) {
        if ( ! is_home() ) {
    	    $options['featured_column'] = false;
        }
      
        return $options;
    }

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

    Let me know if this helps πŸ™‚

    #681938
    Leon

    Thanks a lot, Leo. It worked right away.
    Leon

    #682328
    Leo
    Staff
    Customer Support

    No problem πŸ™‚

    #682513
    Leon

    I see now it doesn’t totally work. On the non-homepages the lay out is the way it should be, but the length of the exerpt still has the length of the “featured post” form the home page.

    Home is: http://l-seven.nl/wordpress/?page_id=12455
    That is the way home should be.

    Non-home is e.g.: http://l-seven.nl/wordpress/?cat=4
    As I wanted it doesn’t have the lay out of the home page featured post but unfortunately it still has the length. Can that be fixed in the snippet?

    Thanks,
    Leon

    #682548
    Leo
    Staff
    Customer Support

    The function above is just for columns.

    How did you set the excerpt length specifically for the featured post?

    #682746
    Leon

    I found this snippet (on this site, I’m sure):

    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 140; // First post
    }

    return $length;
    }

    and made the setting “140”

    Leon

    #683159
    Leo
    Staff
    Customer Support

    That case we need to modify that code:

    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 && is_home() ) {
            return 140; // First post
        }
    
        return $length;
    }
    #687648
    Leon

    Thank you, that worked.

    But now the client wants to maintain the strong and <p> tags in the excerpt. I found a plugin that does that (Advanced Excerpt), but unfortunately it seems to overrule the snippets’s longer “excerpt length” on the homepage.
    Is there a snippet that does the same trick as the plugin? Or can I make the snippet “win” from the the plugin?

    Thanks, Leon

    #688825
    Leo
    Staff
    Customer Support

    Hmm you could try using the more tag to keep the HTML:
    https://docs.generatepress.com/article/using-the-more-tag/

    Or use the custom excerpt box.

    #692254
    Leon

    The more tag works well. I only hope the author will remember to use it in the new “featured post”, and remember to remove it in the old “featured post”.
    Thanks, Leon

    #692631
    Leo
    Staff
    Customer Support

    No problem πŸ™‚

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