This hack will show you how to search Flickr using the phpFlickr class and display the results with links to a larger image and to the Flickr page.
This tip requires a bit of pre-configuration and setup which you can find here and here.
The code is very simple and those of you that have been working with the phpFlickr class this will be very easy.
Here's how it works
The flickr.photos.search will return a list of public photos based on the search parameters supplied. There are 17 search options but only 1 is required (api key) and the rest are optional. For this example well be using three: a list of tags (the key search term), a tag mode ("any" = OR / "all" = AND) and a limit on the number of results.
The great thing about the phpFlickr class is that so much of the dirty work has been done for us that all we need to do is reference the class and a method then pass it some parameters. In the case of the photos_search things are a little different than other functions because instead of passing a list ($param1, $param2, $etc;) we need to pass it an Array(). So in this example we'll create an array with our keyword, a search mode and a results cap and then pass the array to the photos_search function like this:
What we'll get back is a nicely formatted object class of photos. Even though we only specified 3 options we still get back a complete photo object for each photo in the results. You can get more info about what is in the photo object here.
Once we've got our results back we'll do a quick check to be sure we've got some results before we try looping over them. I've stripped out most of the style elements from the output but some are needed to format the results properly. OK so we've got some photo results in the $photos variable and we now need to loop over each photo and get some info to display it.
If you look at the first line in the foreach loop and you can see a reference to $f->buildPhotoURL($photo, "original"). This is another great phpFlickr function that returns a URL to the original photo by using the current $photo and a size parameter. Since this first line is a link we a link to see the photo in it's full size and not the thumbnail which we will be displaying on our page. The next line is the thumbnail image we will display and again we are using the buildPhotoURL function but this time we are passing it the size parameter of "Square" which displays 75x75 pixel thumbnail. Also note the image id tag we are using as well: id='photo_".$photo['id']."' It's not needed in this example but if you add any JavaScript functions this gives you a unique id for each image. The last thing we are going is adding another link so that you can get to the Photo Page that the thubmnail came from back on Flickr.
Once you've got every thing configured you can run this code by pasting it into a page and the passing the page a url prameter like this:
index.php?keyword=bobafett
Congratulations you have now completed a Flickr Photo Search phpFlickr.
did you tested your code?
Parse error: syntax error, unexpected T_STRING
in this line:
$html .= "buildPhotoURL($photo, "original")."' title='".$photo['title']."' target="_blank">";
The code works fine. Thank you.
I think a balance between Marketplace and your own site will be the key. But no details about WP Marketplace have been revealed yet? So it might not even be possible to link back to your site