Next/Previous Post with Post Image

Hello, I found this underneath on the forum to be able to get Next/Previous Post at the end of each post and it worked great. It’s only showing the Title of the post though, is it possible to add the Post Image as well? I’m using Integrity, and a child theme.

function add_entry_navigation(){
if( is_single() || x_is_portfolio_item() ) {
the_post_navigation( array(
‘next_text’ => ‘’ . ‘Next’ . ’ ’ .
’ . ‘Next post:’ . ’ ’ .
%title’,
‘prev_text’ => ‘’ . ‘Previous’ . ’ ’ .
’ . ‘Previous post:’ . ’ ’ .
%title’,
) );
}
}
add_action(‘x_before_view_global__comments-template’, ‘add_entry_navigation’ );

Hello There,

Thanks for writing in!

Yes it is possible to add a featured image of the post in the post navigation. To achieve what you have in mind, please refer to this link: https://stackoverflow.com/a/29060441

Please note that custom coding is outside the scope of our support. Issues that might arise from the use of custom code and further enhancements should be directed to a third party developer.

Hope this helps.

Thanks for your reply. I tried that code, but then nothing shows up at the end of the post?

    // Previous/next post navigation.
$next_post = get_next_post();
$previous_post = get_previous_post();
the_post_navigation( array(
    'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentyfifteen' ) . '</span> ' .
        '<span class="screen-reader-text">' . __( 'Next post:', 'twentyfifteen' ) . '</span> ' .
        '<span class="post-title">%title</span>' . get_the_post_thumbnail($next_post->ID,'thumbnail'),
    'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentyfifteen' ) . '</span> ' .
        '<span class="screen-reader-text">' . __( 'Previous post:', 'twentyfifteen' ) . '</span> ' .
        '<span class="post-title">%title</span>' . get_the_post_thumbnail($previous_post->ID,'thumbnail'),
) );

Hi,

You can try this code instead

function add_entry_navigation(){
if( is_single() || x_is_portfolio_item() ) {
 $next_post = get_next_post();
    $previous_post = get_previous_post();
    the_post_navigation( array(
        'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentyfifteen' ) . '</span> ' .
            '<span class="screen-reader-text">' . __( 'Next post:', 'twentyfifteen' ) . '</span> ' .
            '<span class="post-title">%title</span>' . get_the_post_thumbnail($next_post->ID,'thumbnail'),
        'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentyfifteen' ) . '</span> ' .
            '<span class="screen-reader-text">' . __( 'Previous post:', 'twentyfifteen' ) . '</span> ' .
            '<span class="post-title">%title</span>' . get_the_post_thumbnail($previous_post->ID,'thumbnail'),
    ) );
}
}
add_action('x_before_view_global__comments-template', 'add_entry_navigation' );

As this is all custom development, regretfully we wont be able to assist further. Custom development is outside the scope of our support. We are happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation. If you are not comfortable making further changes and if you require more customization on your site, it would be best to get in touch with a developer.

Thank you for understanding

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.