Using TimThumb with WordPress Post Thumbnails


The WordPress post thumbnails functionality has become a basic necessity of theme coding, but it does have its limitations. Mainly you are stuck with the image sizes you specify in the Settings – Media tab. You can also specify your own image sizes, but clients undoubtedly want to change their image sizes over time or within one website over and over and over and over…. So it makes sense to make use of the dynamic image resizing script TimThumb. I use the following technique to grab the designated featured image post thumbnail from a post and then automatically resize it upon display. Works perfectly!

<!--?php // check if the post has a featured image assigned to it. if ( has_post_thumbnail() ) { // get the src of the large size featured image $src = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), 'large' ); $thumbnailSrc = $src[0]; // output image resized with timthumb ?-->
<a href="&lt;?php the_permalink(); ?&gt;">
<img src="&lt;?php bloginfo('template_directory'); ?&gt;/scripts/timthumb.php?src=&lt;?php echo $thumbnailSrc; ?&gt;&amp;h=420&amp;w=482" alt="" />
</a>
<!--?php } ?-->

From:http://dynabytes.net/wordpress/using-timthumb-with-wordpress-post-thumbnails/

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据