WordPress.org

Ready to get started?Download WordPress

Forums

Next & Previous Post Thumbnails (1 post)

  1. jjkilpatrick
    Member
    Posted 3 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic