• Hello everyone!

    I have a next/prev post navigation enabled in the bottom of the page. However, for some reason some of the posts show incorrect thumbnails. The link to the post is correct, however, the thumbnail is not. Tried to check it on several devices and all show the same so it shouldn’t be a cache related issue. Has anyone encountered this issue?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hi there,

    the GP Theme doesn’t display post thumbnails in the Post Navigation by default so this must be a plugin or custom function that is displaying that.

    Thread Starter maricelo

    (@maricelo)

    Yes, however, I found the solution regarding the thumbnails here – https://generatepress.com/forums/topic/post-navigation-with-clickable-thumbnails/#post-1523670

    Leo

    (@leohsiang)

    I actually tested that solution and it worked correctly:
    https://generatepress.com/forums/topic/post-navigation-with-clickable-thumbnails/#post-1524245

    What do you mean by the thumbnails are not showing correctly?

    Thread Starter maricelo

    (@maricelo)

    Yes, it works for 90% of the posts that I have. I accidentally saw that yesterday.

    Well, for example, I have 3 posts – A, B, C. All of these posts have different featured image set.
    At the end of the post A there is a next/previous post navigation to the post B and C with a thumbnail. And the issue is that for the post B it shows thumbnail from another post on the website. The link to the post is correct but the image is not.
    I checked the same issue in the post D (which has also a link to the post B in the next/prev section) but in this post, the thumbnail is correct and shows the featured image in the post B.

    Hopefully, it is more clear now.

    Theme Author Tom

    (@edge22)

    Hi there,

    Can you share the URL to your website and the exact code you’re using?

    Thanks!

    Thread Starter maricelo

    (@maricelo)

    Unfortunately I can’t share my website URL, however, the code that I am using is below.
    The code is in the functions.php:

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_single() ) {
            $prevPost = get_previous_post();
            $prevThumbnail = isset( $prevPost ) ? get_the_post_thumbnail( $prevPost->ID, 'thumbnail' ) : '';
            $nextPost = get_next_post();
            $nextThumbnail = isset( $nextPost ) ? get_the_post_thumbnail( $nextPost->ID, 'thumbnail' ) : '';
    
            $args['previous_format'] = '<div class="nav-previous">' . $prevThumbnail . '<div class="post-title-wrap"><span class="title-label">Previous Post</span><span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '">' . generate_get_svg_icon( 'arrow-left' ) .'%link</span></div></div>';
            $args['next_format'] = '<div class="nav-next"><div class="post-title-wrap"><span class="title-label">Next Post</span><span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '">%link ' . generate_get_svg_icon( 'arrow-right' ) . '</span></div>' . $nextThumbnail . '</div>';
        }
    
        return $args;
    } );
    add_filter( 'generate_category_post_navigation', '__return_true' );
    Leo

    (@leohsiang)

    Can you remove this part?
    add_filter( 'generate_category_post_navigation', '__return_true' );

    If this doesn’t help, we would need to see the page in question to help.

    Thanks!

    Thread Starter maricelo

    (@maricelo)

    It seems that it helped. Now everything works as expected. Thank you!

    One more thing that I would like to ask. How to place the image in the background of the next/prev navigation? As currently there are 2 divs – one for the name of the article and the second for the picture. Can I somehow combine those in one div so that the picture is in the background across the full width?

    Hi there,

    There are 2 ways of doing this:

    You can either modify the PHP snippet into something like this:

    add_filter( 'generate_post_navigation_args', function( $args ) {
        if ( is_single() ) {
            $prevPost = get_previous_post();
            $prevBackground = isset( $prevPost ) ? get_the_post_thumbnail_url( $prevPost->ID, 'thumbnail' ) : '';
            $nextPost = get_next_post();
            $nextBackground = isset( $nextPost ) ? get_the_post_thumbnail_url( $nextPost->ID, 'thumbnail' ) : '';
    
            $args['previous_format'] = '<div class="nav-previous" style="background-image:url('.$prevBackground.'); background-size:cover;"><div class="post-title-wrap"><span class="title-label">Previous Post</span><span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '">' . generate_get_svg_icon( 'arrow-left' ) .'%link</span></div></div>';
            $args['next_format'] = '<div class="nav-next" style="background-image:url('.$nextBackground.'); background-size:cover;"><div class="post-title-wrap"><span class="title-label">Next Post</span><span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '">%link ' . generate_get_svg_icon( 'arrow-right' ) . '</span></div></div>';
        }
    
        return $args;
    } );

    This adds in the image through inline CSS as a background-image.

    The other way is to keep your current snippet style write a CSS that sets the <img> to position: absolute; and its container to position: relative;

    Example:

    .nav-previous, .nav-next {
    position: relative;
    padding: 20px 20px; 
    }
    
    .nav-previous img, .nav-next img {
    position: absolute;
    width: 100%;
    }

    The padding will control the visible height.

    Thread Starter maricelo

    (@maricelo)

    The issue seems that WordPress is generating a 150×150 pixel thumbnail. And if I try to stretch it then this looks bad. Any ideas on how to adjust the thumbnail size?

    Thread Starter maricelo

    (@maricelo)

    Ok, nvm. Found it. Now just have to adjust the css which is not the easiest for me.

    Thread Starter maricelo

    (@maricelo)

    Could you please help me with one more question? I would like to make the thumbnail in the post navigation to occupy all the width and height of the nav-next class. And “Next post > Post title” (they are in the post-title-wrap class) is on the image in the right bottom corner. I can do that with the css but didn’t manage to change the link to be an image. I would like so that the whole image is clickable but I’m having troubles with nesting it in the link.
    So just to sum up: Image the whole width of the nav-next class. “Next post > Post title” in the right bottom corner but just a simple text.
    The code was taken from: https://generatepress.com/forums/topic/post-navigation-with-clickable-thumbnails/

    #nav-below,
    .nav-previous,
    .nav-next,
    .post-title-wrap {
        display: flex;
        width: 100%;
    }
    
    #nav-below {
        justify-content: space-between;
    
    }
    
    #nav-below img {
        max-width: 100px;
        max-height: 100px;
        object-fit: cover;
    }
    
    .nav-previous,
    .nav-next {
        width: 49%;
        margin: 10px 0;
        position: relative;
        box-sizing: border-box;
    }
    
    .post-title-wrap {
        padding: 10px;
        width: 100%;
        flex-direction: column;
        border: 1px solid #efefef;
    }
    
    .nav-previous .post-title-wrap {
        text-align: right;
    }
    
    #nav-below a:before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
    }
    
    .title-label {
        font-size: 12px;
    }
    
    .nav-previous:hover .post-title-wrap,
    .nav-next:hover .post-title-wrap {
        border: 1px solid #ccc;
    }
    
    @media(max-width: 758px) {
        #nav-below {
            flex-direction: column;
        }
    
        .nav-previous,
        .nav-next {
            width: 100%;
        }
    }

    I’m not sure how to help you out without being able to inspect the site you’re working on.

    Perhaps you could send us the link here – https://generatepress.com/contact/ – so we could check?

    Thread Starter maricelo

    (@maricelo)

    Ok, so in this case could you simply please tell me how to wrap image in link? I guess it is done in the php code posted above.

    Theme Author Tom

    (@edge22)

    You should just be able to wrap the area in a <a> element and then set it to display: block.

    <a href="#something" class="big-link">
        Everything in here
    </a>
    .big-link {
       display: block;
    }

    Just a heads up that custom coding like this is outside the scope of our support – we’re happy to point in the right direction if possible, but we aren’t able to provide full-blown custom solutions.

    Thanks!

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Incorrect thumbnails (next/prev post)’ is closed to new replies.