/ Published in: PHP
Expand |
Embed | Plain Text
<? // usage <?php postimage(180,135);?> // or whatever dimensions you want // requirements: have tim thumb in your theme directory function postimage($width,$height) { $scriptpath = get_bloginfo('template_directory'); $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order')); if (!is_array($attachments)) { $image = $scriptpath."/images/default.gif"; echo '<img src="'.$scriptpath.'/scripts/timthumb.php?src='.$image.'&w='.$width.'&h='.$height.'&zc=1" alt="" />'; } else { $img = array_shift($attachments); $imagelink = wp_get_attachment_image_src($img->ID,'full'); $image = $imagelink[0]; echo '<img src="'.$scriptpath.'/scripts/timthumb.php?src='.$image.'&w='.$width.'&h='.$height.'&zc=1" alt="" />'; } } ?>
Comments
Subscribe to comments
You need to login to post a comment.

How do I use the_title () in the alt and title tags?
How do I use the_title () in the alt and title tags?
Since there is a change in WP 2.9 it doesn´t work with this version anymore. Is there an update available?