Wednesday, November 21, 2012

Create a gallery in zencart using your Flickr sets

Zen Cart is great an all but it really doesn’t do image galleries very well. There are some plugins available but to be honest the admin interface is always a bit erm “clonky” in my opinion. Why not use Flickr to serve up your glorious pictures as a gallery?
Here’s my attempt at getting it to work inspired by work done by Dan Coulter at thehttp://phpflickr.com/ project
1) Create a Flickr account
2) Upload your pictures into groups called “Sets” – giving each a title & description. These will be pulled into your Zen Cart
3) Create an EZ page called “Gallery”
4) In the tpl_page_default.php for your theme (as always ensure you override the default) add the following block of code:
<?php
 if($var_pageDetails->fields['pages_title']=="Gallery"){
// check if there is a query string 'set'
 if($_GET['set']!=""){
 //if there is a query string find out what pos it is in the photosets array
 $setName=$_GET['set'];
$pos=array_search($setName,$photoSetsNames);
echo "<h2>".$setName."</h2>";
 echo "<p>".$photoSetsDescriptions[$pos]."<br/></p>";
 echo $photoSetsPhotos[$pos];
 //print_r($photoSetsDescriptions);
}else{
 // if no query string then display list of all sets
 echo "<ul class=\"galThumbs\">";
foreach($photoSetsNames as $photoset){
 $pos=array_search($photoset,$photoSetsNames);
 ?>
 <li><a href="gallery/?set=<?=$photoset?>">
 <p><?=$photoset?></p>
 <? echo $photoSetsThumbs[$pos];?>
 </a></li>
 <? }
 echo "</ul>";
 }
}
 ?>
5) Upload the two attached files phpFlickr.php and phpFlickrGetSets.php to your “includes\modules” folder phpFlickrGetSets.zip
6) Change the lines indicated in your phpFlickrGetSets.php to be your Flickr App id and the absolute path to your new folder flickr_cache (Note: You absolutely must enable caching otherwise the lookups to Flickr can slow your site down horribly! Plus db caching I found to be woefully slow so stick to file system caching) And your Flickr User Name
(Get your Flickr App Id here: http://www.flickr.com/services/apps/create/apply)
7) Make sure you have created a folder called flickr_cache & set permissions to 755
8) Include your two new modules in the tpl_header.php file like so:
/**
 * load the module for getting the Flickr data
 */
require(DIR_WS_MODULES . zen_get_module_directory('phpFlickrGetSets.php'));
I’m putting it in the site header as I want to dynamically get the list of set names to use in the site menu. If you wanted it only on the gallery page then you could just add it to yourtpl_page_template.php along with the other code above
And Bob’s your uncle:
See it working here: www.dorisdesigns.co.uk

1 comment:

  1. awesome post for creating a gallery in Zen Cart.. thanks yar.. i bookmarked this page.. :) Zen Cart Tutorial For Beginners

    ReplyDelete