Return to Snippet

Revision: 37127
at December 4, 2010 08:12 by vagrantradio

Initial Code
//add support in functions file
add_theme_support( 'post-thumbnails');
add_image_size( 'home-feature', 590, 265, true ); // Homepage Feature Image

//function to call first uploaded image in functions file
function main_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image&order=desc');
  if($files) :
    $keys = array_reverse(array_keys($files));
    $num = $keys[$j];
    $image=wp_get_attachment_image($num, 'large', true);
    $imagepieces = explode('"', $image);
    $imagepath = $imagepieces[1];
    print "<img src='$main' alt='$the_title' class='frame' />";

//goes in template to call image
<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) {
  echo get_the_post_thumbnail($post->ID,array(590, 265));
} else {
   echo main_image();
} ?>

Initial URL

Initial Description
If post thumbnail doesn't exist, then get the first uploaded image. Change sizes as needed.

Initial Title
WordPress Post Thumbs Fallback

Initial Tags

Initial Language