I have picked up a project from a previous developer and he is using this code to generate thumbnails. I need to add a default fallback image and I'm unsure of the best practice.
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="container">
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="entry">
<?php the_content(); ?>
</div>
<?php $categories = get_categories(array('orderby'=>'order','number'=>'13'));
$wud = wp_upload_dir();
$width = get_option('thumbnail_size_w');
$height = get_option('thumbnail_size_h');
$exclude_cats = array(1, 27); // Array of category ID's to exlude from this page
?>
<div id="gallery">
<ul class="cat-list">
<?php foreach ($categories as $cat) {
if (!in_array($cat->cat_ID, $exclude_cats)) : ?>
<li class="cat-item cat-item-<?php echo $cat->cat_ID; ?>">
<a href="<?php echo get_category_link( $cat->term_id ); ?>" title="View all artists under the <?php echo $cat->cat_name; ?> category">
<div class="cat-ss" style="position: relative; width: <?php echo $width; ?>px; height: <?php echo $height; ?>px; overflow: hidden;">
<?php $artists = get_posts('category=' . $cat->cat_ID . '&orderby=rand');
foreach ($artists as $artist) {
$name = get_the_title( $artist->ID );
$thumb = $wud['baseurl'] . '/thumb-' . sanitize_title( $name ) . '-' . $width . 'x' . $height . '.jpg'; ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $name; ?>" title="<?php echo $name; ?>" width="<?php echo $width; ?>" class="cat-ss-image" height="<?php echo $height; ?>" style="position: absolute; top: 0; left: 0;" />
<?php } ?>
<div class="cat-ss-caption png" style="position: absolute; bottom: 0;"><h3><?php echo $cat->cat_name; ?></h3></div>
</div>
</a>
</li>
<?php endif;
} ?>
<ul>
</div>
<div style="clear: both"></div>
</div>
<?php endwhile; ?>
<?php else : ?>
<div class="post">
<h2><?php _e('Not Found'); ?></h2>
</div>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
Looks like his code to pull in a thumb is
So to make it a conditional if/else statement if it's not empty render the image thumbnail, and use a fallback if it is empty, do this (add whatever other code you need to for the image to render):