Archived topic
display feature image in first post of archive
14 replies · Started by Alain Aubry on August 6, 2022
Hi
I am trying to create an archive page with 4 columns, masonry, no feature image, first post larger (or highlighted)... up to here I am fine.
I want to display the feature image just in the first (highlighted) post.. just in the first one.
Can you hint me ?
Thanks
Alain
Hi Alain,
I think we can try a CSS solution.
Can you make the featured images display first using the customizer option?
Let me know :)
yes, it displays all of them, you can check it now.
I want to display ONLY the first one, need to be some kind filter.
CSS can do it, but it will be loading them all
a filter will allow me to change the appearance by category or something...
Hi there,
try this PHP Snippet:
add_filter( 'generate_featured_image_output', function( $output ) {
global $wp_query;
if ( is_category() && 0 != $wp_query->current_post ) {
$output = '';
}
return $output;
} );
YES !!!!
I am amazed, it is exactly what I was looking for.
I can even add some other conditions.
THANK YOU SO MUCH !!!
❤️
You even work on weekends, wow !!!
Glad to be of help :)
Excuse me for re-opening this tread, but I failed to say I am using "Infinite Scroll" in the arquives, so the enabled feature image repeats every 10 posts.
Every 10 post the feature image is enabled. How can I fix this?
Thanks
Alain
Hmmm.... not sure if this will work but you could try checking if is_paged() eg.
if ( is_category() && ( 0 != $wp_query->current_post || is_paged() ) ) {
In that example i check if its NOT the first post OR if it is Paged.
Wow !!! You nailed it again !!!
You guys are geniuses, it is exactly that.
Thank you so much!.
BTW, in a different place, also an arquive, I want to show every featured images but the first make larger, what would be the filter to use ?
I thought of 'generate_blog_image_attributes' but I haven't been able to make it work...
Do you mean the thumbnails size eg. full for first image, medium for other images ?
If so, then this may work:
add_filter( 'generate_page_header_default_size', function( $size ) {
if ( is_category('your target category' ) && 0 != $wp_query->current_post ) {
$size = 'medium';
} else {
$size = 'full';
}
return $size;
} );
It look interesting, I will try later today. I will give feedback.
Were can I get all the filters of the theme? I am always looking for this crazy configurations ...
Thanks
Filters in the theme.... there are so many, and not a central place in the docs for them all, but some you will find here:
https://docs.generatepress.com/collection/filters/
The rest, either sniff around the templates and functions on our GitHub or ask us :)
Hi David
Thank you so much !
I learned a lot, this filters are amazing !
Thank you for the filter list, I was not aware of that page, now I have a lot read and study !
Big thank you for all the team and Tom of course !
Done.
Thank you for the kind words ! We really do appreciate it :)