fall back images for feature post
-
hi im using the following to show the first image in a post if no feature image is set
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { echo get_the_post_thumbnail($post->ID); } else { echo main_image(); } ?>
which calls
//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)); $j=0; $num = $keys[$j]; $image=wp_get_attachment_image($num, 'large', true); $imagepieces = explode('"', $image); $imagepath = $imagepieces[1]; $main=wp_get_attachment_url($num); $template=get_template_directory(); $the_title=get_the_title(); print "<img src='$main' alt='$the_title' class='frame' />"; endif;
id like to take this a bit further and
1. if the first image is displayed have it match the Feature image thumbnails size, other wise its too big.
2. Add a further condition that display a default image if none of the others exist, something like
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { echo get_the_post_thumbnail($post->ID); } else { echo main_image(); } another else if main image doesnt exist then show <img src="<?php bloginfo('template_directory'); ?>/images/default.jpg" alt="<?php the_title(); ?>" /> ?>
but im stumped now!!
ayonne got any ideas, many thanks
- The topic ‘fall back images for feature post’ is closed to new replies.