Vorheriger und nächster Beitrag-Link mit Artikelbild und Zufallsbild als Fallback

Dieser Text wurde am 19. August 2013 veröffentlicht und enthält möglicherweise veraltete Informationen.

single.php

<div id="prev_post">
 <?php
 $prev_post = get_previous_post('true');
 if (!empty( $prev_post )): ?>
 <a href="<?php echo get_permalink( $prev_post->ID ); ?>" title="<?php $prev_post->post_title; ?>" ><?php if ( has_post_thumbnail( $prev_post->ID ) ) { echo get_the_post_thumbnail($prev_post->ID, 'homepage-thumbnail'); } else { ?>
 <img src="<?php bloginfo('template_directory'); ?>/images/artikelbild/start/<?php echo mt_rand(1, 5); ?>.jpg" alt="<?php $prev_post->post_title; ?>" /><?php } ?></a>
 <p><a href="<?php echo get_permalink( $prev_post->ID ); ?>"><?php echo $prev_post->post_title; ?></a></p>
 <?php endif; ?>
</div>

<div id="next_post">
 <?php
 $next_post = get_next_post('true');
 if (!empty( $next_post )): ?>
 <a href="<?php echo get_permalink( $next_post->ID ); ?>" title="<?php $next_post->post_title; ?>" ><?php if ( has_post_thumbnail( $next_post->ID ) ) { echo get_the_post_thumbnail($next_post->ID, 'homepage-thumbnail'); } else { ?>
 <img src="<?php bloginfo('template_directory'); ?>/images/artikelbild/start/<?php echo mt_rand(1, 5); ?>.jpg" alt="<?php $next_post->post_title; ?>" /><?php } ?></a>
 <p><a href="<?php echo get_permalink( $next_post->ID ); ?>"><?php echo $next_post->post_title; ?></a></p>
 <?php endif; ?>
</div>

style.css

#next_post { width:290px; float:right; margin:20px 20px 20px 0; }
#prev_post { width:290px; float:left; margin:20px 0 20px 20px; }