I had asked a question earlier, on getting post-thumbnails from another WP-site. There, the awesome Mike coded a SQL query whose results are then passes on to a PHP array. The piece of code from that answer that I want to modify is this.
$post_urls = $wpdb->get_col($sql);
if (is_array($post_urls))
echo implode("n",$post_urls);
Now the array holds values in the form of <img src="/link/to/image.jpg"/>
. Now how do I..
- Call the WP
image_resize
function on each image URL? - Apply my own CSS class to each image?
UPDATE:
Thanks to Jan for the tips on optimizing the SQL query. Now the $post_urls
array will hold only plain URLs to the images. Can someone show me how to loop through each URL in the array and add prefixes (like <img src="
) and suffixes (like " class="awesome-image"/>
) to each of them?
Calling
image_resize()
would be difficult, since it would search for the image in your main blog’s upload directory. If it is a fixed image size I would just add it to the configuration of your photoblog, so it is created there when you upload new images (you can then rebuild your old image thumbnails).In Mike’s answer you see that he adds the
<img src="
and"/>
parts in the SQL query. That’s nice, but you don’t have to do that. If you leave that off you get just the URL of the image and you can add everything later in PHP. I wrote an alternative version that will provide you with more raw information to play with.I must admit that I do not really know if it is wise to use the power of WP image_resice on HTTP linked images. I would probably formulate an additional question to find out more about needs.Probably something like:
How do I display a smaller version of an image I have linked in an HTML IMG tag?
As for the rest of the magic with PHP, this probably is doing what you’re asking for. I found this ancient magic formula which should to the magic according to the book I’ve found it in:
May the force be with you and good luck improving your magic skills for the future!
If you want to resize the image you need to download the image from the webserver and then write it to disk. The below function should do the trick. The image is then stored on the local hard drive. This is actually much more friendly then loading the thumbnails from another site.
since this function uses GD u can simply add some resizing code to it there are plenty of examples for that.