WordPress.org

Support

Support » Plugins and Hacks » Hacks » Next & Previous Post Thumbnails

Next & Previous Post Thumbnails

  • I am building a custom theme and i’m using the post thumbnail function to show next and previous posts in my sidebar.

    Here is the code i’m using

    <div class="previmg">
    <?php $post_thumbnail = get_post_meta($post->ID, 'post_thumbnail', true);
    if ($post_thumbnail) {
    ?>
    <a href="<?php previous_post_link(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo $post_thumbnail; ?></a>
    
    <?php } else { ?>
    
    <?php $prevPost = get_previous_post(); $prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(66,66) ); previous_post_link('%link',''.$prevthumbnail.'', TRUE); ?>
    
    <?php } ?>
    
    </div>
    
    <div class="nextimg">
    <?php $post_thumbnail = get_post_meta($post->ID, 'post_thumbnail', true);
    if ($post_thumbnail) {
    ?>
    <a href="<?php next_post_link(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo $post_thumbnail; ?></a>
    
    <?php } else { ?>
    
    <?php $nextPost = get_next_post(true); $nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(66,66) ); next_post_link('%link',''.$nextthumbnail.'', TRUE); ?>
    
    <?php } ?>
    </div>

    I am having a problem in showing a default thumbnail (for example a empty thumbnail with a cross) when you get to the very last post or the very first post.

    Any ides on how to do this?

  • The topic ‘Next & Previous Post Thumbnails’ is closed to new replies.
Skip to toolbar