Need to use a relative image path with TimThumb.php

efeezy

New member
Oct 5, 2007
5,250
136
0
50
For some reason the thumbnail images on my site are not being displayed correctly with the image path that TimThumb.php is pulling from. Here's the code I'm currently using on my archive and cat pages.

Code:
<div class="grid-image"><a class="hover_play_small" href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/scripts/timthumb.php?src=<?php echo $image[0]; ?>&w=76&h=60" alt="<?php the_title(); ?>" /></a><?php echo $icon; ?></div>
<?php else: ?>
<div class="grid-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/scripts/timthumb.php?src=<?php echo $attachment[0]; ?>/images/thumbnail.png&w=76&h=60" alt="<?php the_title(); ?>" /></a><?php echo $icon; ?></div>

The broken thumbnail that is displayed shows this image path;

Code:
http://w w w.mywebsite.com/wp-content/themes/AwesomeTheme/scripts/timthumb.php?src=[COLOR="Yellow"]http://w w w.mywebsite.com[/COLOR]/wp-content/uploads/2013/02/imagename-76x60.jpg&w=76&h=60

I some how need the image path to be relative and remove the http:// w w w.mywebsite.com directly after the ?src=

When I remove that, the image path can be found, but I have no idea how to make this work in the code at the top. Any ideas would be great. Thanks.
 


What does the function that outputs the $image variable looks like? I'd suggest to look there.
 
Quick but dirty fix:
Code:
<div class="grid-image"><a class="hover_play_small" href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/scripts/timthumb.php?src=<?php echo str_replace('http:// w w w.mywebsite.com','',$image[0]); ?>&w=76&h=60" alt="<?php the_title(); ?>" /></a><?php echo $icon; ?></div>
<?php else: ?>
<div class="grid-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/scripts/timthumb.php?src=<?php echo str_replace('http:// w w w.mywebsite.com','',$attachment[0]); ?>/images/thumbnail.png&w=76&h=60" alt="<?php the_title(); ?>" /></a><?php echo $icon; ?></div>

The above code does exactly as you need and removes "http:// w w w.mywebsite.com" from the URL.

But as ShadowCaster mentioned, you should look at the $image and $attachment variables. Without knowing anything about those arrays, the other array keys may contain the output you're looking for (without the domain in the value). Using that would be a cleaner way of attacking this.