Site logo

Archived topic

Only show post as "Featured post" on homepage

11 replies · Started by Leon on September 18, 2018

Viewing posts 1–12 of 12

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

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 :)

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

No problem :)

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

The function above is just for columns.

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

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

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;
}

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

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

No problem :)

This archived topic is closed to new replies.