• Hello.

    I wish to make navigation to previous and next post (inside same category) using featured image thumbnail image instead of text links.

    So far I made it working great for previous and next post inside same category. Than I realized that I have some free space to show previous two and next two post if exist.

    This is what I have.

    <?php
    $prev_post = get_previous_post(TRUE);
    $prev_post_thumb_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($prev_post->ID), 'thumbnail');
    if (!empty( $prev_post )): ?>
    <a href="<?php echo get_permalink( $prev_post->ID ); ?>"<img src="<?php echo $prev_post_thumb_image_url[0]; ?>"></a>
    <?php endif; ?>
    
    <?php
    $next_post = get_next_post(TRUE);
    $next_post_thumb_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($next_post->ID), 'thumbnail');
    if (!empty( $next_post )): ?>
    
    <a href="<?php echo get_permalink( $next_post->ID ); ?>"><img src="<?php echo $next_post_thumb_image_url[0]; ?>"></a>
    <?php endif; ?>

    This will check and display previous and next post featured image, if exist.

    How to check if there is two next/previous post in same category and to show featured image of them, and if there is no two next/previous posts to show just one next/previous post (if exist at least one)?

  • The topic ‘Previous and next navigation using featured image thumbnail?’ is closed to new replies.