Site logo

Archived topic

Post navigation thumbnails clickable with link

6 replies · Started by Michel on March 1, 2021

Viewing posts 1–7 of 7

Hi,

I use the following code for previous/next navigation in single posts.

add_filter( 'generate_post_navigation_args', function( $args ) {
    if ( is_single() ) {
        $prevPost = get_previous_post(true);
        $prevThumbnail = isset( $prevPost ) ? get_the_post_thumbnail( $prevPost->ID ) : '';
        $nextPost = get_next_post(true);
        $nextThumbnail = isset( $nextPost ) ? get_the_post_thumbnail( $nextPost->ID ) : '';

        $args['previous_format'] = '<div class="nav-previous">Previously:<br>' . $prevThumbnail . '<br><span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '">%link</span></div>';
        $args['next_format'] = '<div class="nav-next">Next:<br>' . $nextThumbnail . '<br><span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '">%link</span></div>';
    }

    return $args;
} );

One thing eludes me: making the thumbnail clickable with the next/previous link. How can that function add it?

Is there any chance to find a tip regarding this?

Hi Michel,

Have you considered using GPP 2.0 which is in the Alpha version currently?

The block element now allows you to design custom post navigation without any coding at all.

See the Post Navigation Templates section of this article here:
https://generatepress.com/introducing-the-gp-theme-builder/

And more info on dynamic data and blocks:
https://docs.generatepress.com/article/dynamic-data/
https://docs.generatepress.com/article/dynamic-blocks/

Please keep in mind that we reply to every question within 24 hours - most of the time it's much shorter.

Hmmm. Haven't made the transition to the block editor yet, and using an alpha version on a production site may be a bit much for me.

Is there any workaround for between now and that kind of transition?

This works. All I have to do now is to customise the CSS a little. Thanks! 🙂

No problem :)

This archived topic is closed to new replies.