The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Previous and next navigation using featured image thumbnail? (1 post)

  1. jole5
    Posted 2 years ago #


    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.

    $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; ?>
    $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)?

Topic Closed

This topic has been closed to new replies.

About this Topic