• Resolved fukr

    (@fukr)


    How to Use Thumbnails for Previous/Next Navigation in WordPress?
    I searched on the internet and there were sevearl solutions but not work for me.

    Here is one example i used but failed:

    <?php
    $prevPost = get_previous_post();
    $prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(150,150) );
    previous_post_link('%link',''.$prevthumbnail.'', TRUE);
    ?>
    
    <p class="prev_next2"><?php previous_post_link('%link','<') ; ?>
    
    <?php
    $nextPost = get_next_post();
    $nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(150,150) );
    next_post_link('%link',''.$nextthumbnail.'', TRUE);
    ?>
    <p class="prev_next2"><?php previous_post_link('%link','>') ; ?></p>

Viewing 2 replies - 1 through 2 (of 2 total)
  • can you define ‘failed’ with some more words?
    possibly with a link to the problem?

    are you trying to add the navigation to the single post template single.php (where it should work), or to the index template (where it will not work)?

    there is primarily nothing wrong with the code, apart that it does not provide a default if no thumbnail (aka ‘featured image’) is set.

    Thread Starter fukr

    (@fukr)

    Thanks alchymyth. “failed” because it won’t display thumbnails but links…
    Though i still think there is nothing wrong wirh the code, i still cant figure out why it won’t work for me.

    Any way, i find another way to use thumbnail navigation:

    <?php
    $prev_post = get_previous_post();
    if (!empty( $prev_post )): ?>
      <a href="<?php echo get_permalink( $prev_post->ID ); ?>"><?php echo get_the_post_thumbnail($prev_post->ID, 'thumbnail', array(120,120)); ?></a>
    <?php endif; ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to display next/previous post thumbnail’ is closed to new replies.