Skip to main content
  • Home
  • Work
  • Photography
  • Contact
  • Client Login
New Rivers Digital
Home Blogs Eric Weik's blog

Implementing Flickr Slideshow Links By Theming Flickr.module

In:
  • Drupal
  • Drupal Recipes
  • Flickr
  • Flickr.module
  • Theming
17Jan2010

I've implemented a "slideshow" feature on the photosets in the Photography section of this site (and in blog posts that feature photosets). This feature links to Flickr's built-in slideshow by theming the output of the Flickr module for Drupal:

In this Drupal recipe, we will look at how this was achieved.

Step 1: Review Flickr.module's theming functions.

Lets first open the flickr/flickr.module file and search for "theme_" to see what theming functions it provides. As of version 6.x-1.1, I see the following theme functions:

  • function theme_flickr_photo($p, $size = NULL, $format = NULL, $attribs = NULL)
  • function theme_flickr_photo_box($p, $size = NULL, $format = NULL, $attribs = NULL)
  • function theme_flickr_photos($uid, $photos)
  • function theme_flickr_photoset($ps, $owner, $size, $attribs = NULL)

By looking through the code (or examining the page output with Firebug), it looks like theme_flickr_photoset() is generating the #flickr-photoset div that holds all of the photos in a photoset, so lets override it to put a "view as a slideshow" link at the top. While you have this file open, select all of the theme_flickr_photoset() function (from the function declaration to the closing bracket) and copy it to your clipboard.

Step 2: Create a theme override.

Now go to the theme for your site, open up template.php, scroll down to the bottom, paste in theme_flickr_photoset(), and change the function declaration to the following (changing "YOURTHEME" to the name of your current theme):

function YOURTHEME_flickr_photoset($ps, $owner, $size, $attribs = NULL) {

Now flush the theme registry (by either visiting the Themes page, or simply clearing all caches). The next time Flickr.module calls theme('flickr_photoset'), our new theme override will be called instead of the built in theme function. But so far it still looks exactly the same as the original, so next, lets customize it.

Step 3: Customize the new theme override.

After doing a quick examination of the parameters passed to the theme_flickr_photoset() function (using dpm($ps), dpm($owner), etc.), I added the following to the new theme function:

<?php
    $output
.= "<div class='flickr-photoset'>\n";

       

/*** NRD - BEGIN custom theme code.*/   
        // Build a link to this photoset on Flickr
       
$flickr_photoset_url = 'http://www.flickr.com/photos'.'/'.
                              
$ps['owner'].'/'.
                              
'sets'.'/'.
                              
$ps['id'];
       
// Output a link to the slideshow feature on Flickr
       
$output .= '<div class="flickr-slideshow">'.
                  
l("View complete photoset as a Slideshow (on Flickr)",
                    
$flickr_photoset_url.'/show',
                     array(
'attributes' => array('title' => 'Flickr Slideshow'), 'absolute' => TRUE)
                   ).
                  
'</div>';
       
/*** NRD - END custom theme code.*/
?>

This code first builds a link to the photoset on Flickr, and stores it in $flickr_photoset_url. It then uses this url to output a div containing nothing but a link to the Flickr slideshow.

Load a page containing a Flickr photoset, and you should see the new link! Add some CSS to style this link and you are done!

Review

So to review, you should copy the code from theme_flickr_output() and merge the slideshow code above into it via a new theme override function YOURTHEME_flickr_output(). As of flickr-6.x-1.1, the complete override should look something like this:

<?php
/**
* Override the flickr_photoset template.
*
* @param $ps
*   An array of variables about the photoset.
* @param $owner
*   The flickr owner id.
* @param $size
*   Size to display photos (for theme_flickr_photo() call).
* @param $attrib
*   Attribute array (for flickr_img() call).
*/
function YOURTHEME_flickr_photoset($ps, $owner, $size, $attribs = NULL) { 
  if (
module_exists('flickr_sets')) {
   
$output .= "<div class='flickr-photoset'>\n";

       

/*** NRD - BEGIN custom theme code.*/   
        // Build a link to this photoset on Flickr
       
$flickr_photoset_url = 'http://www.flickr.com/photos'.'/'.
                              
$ps['owner'].'/'.
                              
'sets'.'/'.
                              
$ps['id'];
       
// Output a link to the slideshow feature on Flickr
       
$output .= '<div class="flickr-slideshow">'.
                  
l("View complete photoset as a Slideshow (on Flickr)",
                    
$flickr_photoset_url.'/show',
                     array(
'attributes' => array('title' => 'Flickr Slideshow'), 'absolute' => TRUE)
                   ).
                  
'</div>';
       
/*** NRD - END custom theme code.*/
       
   
$photos = flickr_set_load($ps['id']);
    foreach ((array)
$photos['photoset']['photo'] as $photo) {
     
//insert owner into $photo because theme_flickr_photo needs it
     
$photo['owner'] = $owner;
     
$output .= theme('flickr_photo', $photo, $size);
    }
       
$output .= '</div>';
    return
$output;
  } else {
   
$img = flickr_img($ps, $size, $attribs);   
   
$output = theme('pager', NULL, variable_get('flickr_photos_per_page', 20));
   
$photo_url = flickr_photoset_page_url($owner, $ps['id']);   
   
$output .= "<div class='flickr-photoset'>\n";
   
$title = is_array($ps['title']) ? $ps['title']['_content'] : $ps['title'];  
    return
l($img, $photo_url, array('attributes' => array('attributes' => array('title' => $title), 'absolute' => TRUE, 'html' => TRUE)));
  }
}
?>
  • Eric Weik's blog

Comments

#1 Update

Eric Weik's picture

Submitted by Eric Weik on Sun, 01/17/2010 - 22:19.

Update: I made a minor change to the code (removed the 'rel' attribute in the call to l()). It was leftover from when I was experimenting with some lightbox integration. It didn't break, but it didn't need to be there either.

  • reply

#2 Related Tutorial

Eric Weik's picture

Submitted by Eric Weik on Tue, 02/02/2010 - 17:26.

For a complete tutorial on implementing a photo gallery with Drupal, Flickr, CCK, and Views, check out Chris Free's article Create a Drupal Photo Gallery Using Flickr, CCK & Views.

-Eric

  • reply

Post new comment

Warning
I strongly encourage and welcome links and feedback. However, this site is moderated and comments with inappropriate links are rejected. Please do not post a one-line "Me too" or "Great post!" comment just so you can link to your site. Thank you for your understanding.
The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Use to create page breaks.

More information about formatting options

Blog Posts (RSS)

About

Hello! My name is Eric Weik. I am a computer scientist, photographer, musician, and occasional blogger. New Rivers Digital is my software consulting business. I am dedicated to using open source software and open data standards for Web development and applications integration. In particular, I am an ardent Drupal fan and specialize in Drupal module development, theming, and data architecture integration.

New Rivers Digital
PO Box 784

Lancaster, VA 22503

Voice+1-804-462-3219
Fax +1-804-462-3229
Contact Form

Content Tags

Abstract B&W Bookmarklet Celestial Date Drupal Drupal Recipes Drupal Sites Dynamic Range Estuary Etsy Flickr Flickr.module Macro Meggy Jr MySQL MySQL Recipes New Rivers Digital Photoblog Photo Expedition Photoset PHP Snow Sunset Theming Token.module Trigger.module Views.module Webform.module Web Standards Zen Zen Theming
more tags

Recent comments

  • Default Behavior
    1 week 6 days ago
  • One possibility...
    1 week 6 days ago
  • Puzzling
    1 week 6 days ago
  • Thank you once again for your
    1 week 6 days ago
  • How rude of me, I didn't
    1 week 6 days ago
  • Field identifiers, dpm, etc.
    1 week 6 days ago

Popular content

Today's:

  • Using Drupal Actions, Triggers, and Tokens to Send Notifications About Comments
  • Session Data in Drupal: DO NOT USE sess_read() and sess_write()!
  • Weekly Photoblog 2010 - Week 04

All time:

  • Using Drupal Actions, Triggers, and Tokens to Send Notifications About Comments
  • Sending Multiple Customized Confirmation Messages with Webform.Module
  • Implementing Flickr Slideshow Links By Theming Flickr.module

Activity Stream

  • Tue, 03/09/2010 - 18:21

  • Del.icio.us Eric linked to Bioluminescent Plankton: What makes it glow? | Aquaviews – Online SCUBA Magazine 6:21pm#
  • Wed, 03/03/2010 - 20:22

  • Del.icio.us Eric linked to The Farm Diary: Day By Day...  8:22pm#
  • Del.icio.us Eric linked to The Brads – a comic about web design 11:29am#
  • Wed, 02/24/2010 - 23:16

  • Del.icio.us Eric linked to Sail Calculator Pro v3.53 - 2000+ boats 11:16pm#
  • Del.icio.us Eric linked to Blue Heron Chapter - Home 11:15am#
  • Del.icio.us Eric linked to MAKEDO - Shop 11:14am#
  • Mon, 02/22/2010 - 22:44

  • Del.icio.us Eric linked to Lytha Studios KumiPlanner - Kumihimo Pattern Design Application 10:44pm#
  • Fri, 02/19/2010 - 23:20

  • Del.icio.us Eric linked to Green Sea Slug Is Part Animal, Part Plant | Wired Science | Wired.com 11:20pm#
  • Del.icio.us Eric linked to The Only Immortal Animal on Earth  | Environmental Graffiti 11:19pm#
  • Del.icio.us Eric linked to EDGE 11:12pm#
more from my activity-stream


I am a member of the Drupal Association.
Eric At NRD on Drupal.org
Circumjacence (Eric Weik) on Twitter
Circumjacence on Delicious
Eric Weik on Linkedin
Circumjacence (Eric Weik) on Flickr
Circumjacence (Eric Weik) at StumbleUpon

Powered by Drupal & Genesis | Valid XHTML 1.0 Strict | Syndicate content RSS Feed

© 2009 New Rivers Digital | PO Box 784 | Lancaster, Virginia 22503 | +1-804-462-3219 | Contact Form