Are you looking for the finest and most effective thumbnail function for wordpress to represent your wordpress post in your favorable way. Then download this finest thumbnail script.
Step1:
Download Thumbnail Script for wordpress and unzip it. Keep the scripts folder inside your theme folder.
Step2:
Copy and paste this function inside the functions.php file of your theme folder.
[php]
<?php
function show_thumb($width,$height,$crop,$quality) {
global $post;
$custom_field_value = get_post_meta($post->ID, ‘thumbnail’, true);
$attachments = get_children( array(‘post_parent’ => $post->ID, ‘post_status’ => ‘inherit’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order ID’, ‘numberposts’ => 1) );
if ($attachments == true) {
foreach($attachments as $id => $attachment) {
$img = wp_get_attachment_image_src($id, ‘full’);
$img_url = parse_url($img[0]);
$img_url = $img_url[‘path’];
print ‘<a href="’.get_permalink($post).’" title="’.$post->post_title.’"><img src="’.get_template_directory_uri().’/scripts/phpThumb/phpThumb.php?src=’.$img_url.’&w=’.$width.’&h=’.$height;
if ($crop == 1) echo ‘&zc=T’;
if ($crop == 2) echo ‘&zc=C’;
if ($crop == 3) echo ‘&zc=B’;
if ($crop == 4) echo ”;
echo ‘&q=’.$quality;
print ‘" alt="’.$post->post_title.’" /></a>’;
}
} elseif ($custom_field_value == true) {
$tweak = str_replace(‘/’, ‘%2F’, $custom_field_value);
$img_url = str_replace(‘:’, ‘%3A’, $tweak);
print ‘<a href="’.get_permalink($post).’" title="’.$post->post_title.’"><img src="’.get_template_directory_uri().’/scripts/phpThumb/phpThumb.php?src=’.$img_url.’&w=’.$width.’&h=’.$height;
if ($crop == 1) echo ‘&zc=T’;
if ($crop == 2) echo ‘&zc=C’;
if ($crop == 3) echo ‘&zc=B’;
if ($crop == 4) echo ”;
echo ‘&q=’.$quality;
print ‘" alt="’.$post->post_title.’" /></a>’;
}
}
?>[/php]
Step:3
How to use it?
Its so simple just call this function
[php]<?php show_thumb(150,150,1,95); ?>[/php]
you have to use it inside a wordpress loop like below, here the first parameter is width, second one is height, third one is crop from the position, for value 1 in third parameter it will crop the image from the top, for value 2 it will crop the image from the middle and for value 3 it will crop the image from bottom. In this way you can adjust your thumbnails.
[php] <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<div class="post-con">
<div class="entry">
<?php show_thumb(150,150,1,95); ?>
<?php the_content_limit(470, ”); ?>
</div>
</div>
<div class="postmetadata">
<?php the_tags(‘Tags: ‘, ‘, ‘, ‘ | ‘); ?>
Category: <?php the_category(‘, ‘) ?><br />
by: <em><?php the_author() ?></em> on: <em><?php the_time(‘F jS, Y’) ?></em>
<div class="comments"><span><?php comments_number(0, 1, ‘%’); ?></span> Comments</div>
</div>
</div>
<?php endwhile; ?>[/php]
3 responses to “Most effective thumbnail creator for wordpress”
Hi Kafi
no…I wasn’t talking about using it with a plugin. I was hoping to use within theme files to display thumbnails for related posts…I already had the code for displaying related posts without using a plugin.
I did get your codes working with the related posts code…only I couldn’t figure out how to make it display a default image if no image was present.
Are you talking about related post plugin? It will work with everything but to use it inside a plugin you have to modify the plugin code. The use is simple if you use it inside theme files.
I used your code and it really is excellent :)… do you think it’s possible to adapt it to display the thumbnails for related posts? …(based on category as opposed to tags)