Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Update this script so all images use tim thumb WordPress

  • SOLVED

I have this script which currently just makes images form an external link use tim thumb, i want all images to use timthumb if possible (or happy to take other suggestions that will show a resized image without actually having to go and manually resize it).

Here's the script


<?php
if ( has_post_thumbnail() ) {
echo '<div class="post_wp_thumb" >';
the_post_thumbnail('single-post-thumbnail');
echo '</div>';
} else {
echo '<div class="post_wp_thumb_comm" style="border: 1px solid #EFEFEF;text-align: center;">';
$image_link = get_first_image();
$permalink = get_permalink($post->ID);
if ($image_link != "external"){
echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. $image_link .'&h=100&w=100&zc=1" alt="online shopping" title="online shopping" height="100" width="100"> </a>';
} else {
echo '<a href="'. $permalink .'"> <img src="'. get_first_image_2() .'" height="100" width="100" alt="Shop it!" title="online fashion"> </a>';

}

echo '</div>';

}


?>

Answers (4)

2012-01-24

Arnav Joy answers:

try this


<?php

if ( has_post_thumbnail() ) {

$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');


echo '<div class="post_wp_thumb" >';

echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. $large_image_url[0] .'&h=100&w=100&zc=1" alt="Shop it!" title="online fashion"> </a>';

echo '</div>';

} else {

echo '<div class="post_wp_thumb_comm" style="border: 1px solid #EFEFEF;text-align: center;">';

$image_link = get_first_image();

$permalink = get_permalink($post->ID);

if ($image_link != "external"){

echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. $image_link .'&h=100&w=100&zc=1" alt="online shopping" title="online shopping" height="100" width="100"> </a>';

} else {

echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. get_first_image_2() .'&h=100&w=100&zc=1" alt="Shop it!" title="online fashion"> </a>';



}



echo '</div>';



}





?>


kateM82 comments:

Worked like a charm, thanks!


Arnav Joy comments:

or try this

if ( has_post_thumbnail() ) {

$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'single-post-thumbnail');


echo '<div class="post_wp_thumb" >';

echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. $large_image_url[0] .'&h=100&w=100&zc=1" alt="Shop it!" title="online fashion"> </a>';

echo '</div>';

} else {

echo '<div class="post_wp_thumb_comm" style="border: 1px solid #EFEFEF;text-align: center;">';

$image_link = get_first_image();

$permalink = get_permalink($post->ID);

if ($image_link != "external"){

echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. $image_link .'&h=100&w=100&zc=1" alt="online shopping" title="online shopping" height="100" width="100"> </a>';

} else {

echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. get_first_image_2() .'&h=100&w=100&zc=1" alt="Shop it!" title="online fashion"> </a>';



}



echo '</div>';



}


kateM82 comments:

Actually spoke to soon. Worked like a charm in one spot, tried to apply it within a php widget and I get this error

Parse error: syntax error, unexpected '=', expecting ',' or ';' in /home/ddgd/public_html/wp-content/themes/thesis_18/custom/custom_functions.php(508) : eval()'d code on line 34

Full code is here:



<div class="just-added-comms-hp" style="float: left; width: 270px; ">

<?php $temp_query = $wp_query; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$sticky=get_option('sticky_posts');
$args=array(
'caller_get_posts'=>1,
'post_type' => 'dshop',
'dshop-type' => 'favourite',
'orderby'=> rand,
'post__not_in' => $sticky,
'paged'=>$paged,
'posts_per_page'=>9,
);
//query_posts($args);
$my_query = new WP_Query($args);

while ($my_query->have_posts()) : $my_query->the_post();
?>
<div class="swagshop_about" style="width:75px;margin-right: 9px; height: 75px; margin-bottom:10px;padding-right: 5px;">
<?php
if ( has_post_thumbnail() ) {
echo '<div class="post_wp_thumb" >';
the_post_thumbnail('single-post-thumbnail');
echo '</div>';
} else {
echo '<div class="post_wp_thumb_comm" style="border: 1px solid #EFEFEF;text-align: center; width: 75px; height: 75px;">';
$image_link = get_first_image();
$permalink = get_permalink($post->ID);
if ($image_link != "external"){
echo '<a href="'. $permalink .'"> <img src="/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. $image_link .'&h=70&w=70&zc=1" alt="online fashion" title="online shopping" width="70" height="70" style="width: 70px; height: 70px;"> </a>';
} else {
echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. get_first_image_2() .'&h=70&w=70&zc=1" alt="Shop it!" title="online fashion" height="70" width="70"> </a>';
}

echo '</div>';

}


?>

</div>

<div class="post-theme post" id="post-<?php the_ID(); ?>">
<div class="clear"></div>
</div>

<!-- Post -->
<?php endwhile; ?>
<br class="clear" />

<?php
$wp_query = $temp_query;
wp_reset_query();
?>


</div>


Arnav Joy comments:

can you paste here line no. 34 complete

2012-01-24

Andrew Wong answers:

You already have TimThumb for the feature image, only the default image doesn't use TimThumb. Check how $image_link URL looks like and you should be fine with the TimThumb for the default image...?

2012-01-24

Romel Apuya answers:

have you tried something like this?

<?php
if ( has_post_thumbnail() ) {
echo '<div class="post_wp_thumb" >';
the_post_thumbnail('single-post-thumbnail');
echo '</div>';
} else {
echo '<div class="post_wp_thumb_comm" style="border: 1px solid #EFEFEF;text-align: center;">';
$image_link = get_first_image();
$permalink = get_permalink($post->ID);
if ($image_link != "external"){

echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. $image_link .'&h=100&w=100&zc=1" alt="online shopping" title="online shopping" height="100" width="100"> </a>';
} else {
echo '<a href="'. $permalink .'"> <img src="http://images.dropdeadgorgeousdaily.com/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. get_first_image_2().'&h=100&w=100&zc=1" height="100" width="100" alt="Shop it!" title="online fashion"> </a>';
}
echo '</div>';
}
?>


2012-01-24

Kannan C answers:

@Arnav Joy: Hey Dude, i respect your answers but why don't you use code wrap for your codes? It looks annoying. Please try to make use of code wrap.