[Resolved] display feature image in first post of archive

Home Forums Support [Resolved] display feature image in first post of archive

Home Forums Support display feature image in first post of archive

  • This topic has 14 replies, 3 voices, and was last updated 1 week ago by David.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #2304900
    Alain Aubry

    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

    #2305341
    Leo
    Staff
    Customer Support

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

    #2305379
    Alain Aubry

    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

    #2305382
    Alain Aubry

    a filter will allow me to change the appearance by category or something…

    #2305643
    David
    Staff
    Customer Support

    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;
    } );
    #2305734
    Alain Aubry

    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 !!!

    #2305762
    David
    Staff
    Customer Support

    Glad to be of help πŸ™‚

    #2306696
    Alain Aubry

    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

    #2306713
    David
    Staff
    Customer Support

    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.

    #2306781
    Alain Aubry

    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…

    #2306789
    David
    Staff
    Customer Support

    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;
    } ); 
    #2306955
    Alain Aubry

    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

    #2306960
    David
    Staff
    Customer Support

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

    #2308292
    Alain Aubry

    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.

    #2308737
    David
    Staff
    Customer Support

    Thank you for the kind words ! We really do appreciate it πŸ™‚

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