WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Next & Prev Post (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 if(get_adjacent_post(false, '', true)) : // check for the existance of a prev post ?>
    
                                <?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 } ?>
    
                                <?php else : // if no prev post ?>
    
                                <img src="<?php bloginfo('template_url'); ?>/images/empty.jpg"/>
    
                                <?php endif; // end of the prev post check ?>
    
    </div>
    
    <div class="nextimg">  
    
    								<?php if(get_adjacent_post(false, '', false)) : // check for the existance of a next post ?>
    
                                    <?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 } ?>
    
                                    <?php else : // if no prev post ?>
    
                                    <img src="<?php bloginfo('template_url'); ?>/images/empty.jpg"/>
    
                                    <?php endif; // end of the prev post check ?>
    
                                </div>

    I'm having a issue when I get the the forth post. It seems to just show an empty image which I dont want.

    Any ideas on how to fix it?

    Thanks

    - - - - - - -

    http://itdrewitself.com/illustration/landfill-editions/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.