<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Themocracy WordPress Themes &#187; flickr</title>
	<atom:link href="http://themocracy.com/tag/flickr/feed/" rel="self" type="application/rss+xml" />
	<link>http://themocracy.com</link>
	<description>WordPress Theme Design</description>
	<lastBuildDate>Thu, 18 Aug 2011 07:34:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>A Flickr Badge using WordPress Shortcodes</title>
		<link>http://themocracy.com/2010/03/a-flickr-badge-using-wordpress-shortcodes/</link>
		<comments>http://themocracy.com/2010/03/a-flickr-badge-using-wordpress-shortcodes/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 11:22:30 +0000</pubDate>
		<dc:creator>Barrie</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://themocracy.com/?p=271</guid>
		<description><![CDATA[Flickr provides a neat little snippet of javaScript to supply various image galleries direct to your site - a so-named Flickr badge. Here's a good way using WordPress shortcodes to grab a gallery...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fthemocracy.com%2F2010%2F03%2Fa-flickr-badge-using-wordpress-shortcodes%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fthemocracy.com%2F2010%2F03%2Fa-flickr-badge-using-wordpress-shortcodes%2F" height="61" width="51" /></a></div><p><img src="http://themocracy.com/wp-content/uploads/2010/03/flickr-wordpress.jpg" alt="Flickr" title="flickr-wordpress" width="160" height="148" class="alignright size-full wp-image-272" /><strong>Flickr provides a neat little snippet of javaScript to supply various image galleries direct to your site &#8211; a so-named Flickr badge.</strong></p>
<p>So if your gallery is on Flickr &#8211; rather in your WordPress, which has its own gallery shortcode &#8211; a shortcode in the blog post content can be used to embed a gallery of thumbnail images, which is also a good way to demonstrate the various usages of WordPress shortcodes.</p>
<p>The HTML for a flickr badge looks something like this:-</p>
<pre class="brush: html">

&lt;div class=&quot;flickr_badge&quot;&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.flickr.com/badge_code_v2.gne?count=5&amp;display=latest&amp;size=m&amp;layout=h&amp;source=all_tag&amp;tag=fish&quot;&gt;&lt;/script&gt;&lt;/div&gt;
</pre>
<p>And the parameters work like this:-</p>
<p><strong>count</strong> <em> integer</em> 1-10. Default is 10.</p>
<p><strong>display</strong> <em>string</em> &#8216;latest&#8217; or &#8216;random&#8217;  Default is latest. </p>
<p><strong>layout</strong> <em>string</em> h, v, x - Photos are listed horizontally, vertically, or no style. Default is horizontal.  </p>
<p><strong>source</strong> <em>string</em> user, user_tag, user_set, group, group_tag, all, all_tag </p>
<p>Source implies which &#8216;account&#8217; the photos come from:- a specified user, a user set, a group, or all users, then filtered by tag if required.  Further parameters may then be required, user(ID string)  tag (string), group (integer), and set (integer,  the url …/sets/1234567/).  </p>
<p><strong>size</strong> <em>string</em> s, t, m   s stands for square (cropped, not small&#8230;), t for thumbnail, and m for medium.  t = thumbnail is the default.</p>
<p>(<a href="http://idgettr.com/">idgettr</a> is very useful for figuring out user IDs and the IDs for photosets, groups etc.)</p>
<p><strong>WordPress Shortcodes</strong></p>
<p>A shortcode has a &#8220;handler function&#8221; &#8211; which is integrated into the code by calling the function <strong>add_shortcode()</strong>. The purpose here is to supply the various parameters for our Flickr badge as parameters of the function &#8211; the query string for the Flickr call is then constructed and the javascript code output to the page.</p>
<p>In <strong>functions.php</strong></p>
<pre class="brush: php">

function flickr_badge_shortcode($atts){

//Here&#039;s our defaults
$query_atts = shortcode_atts(array(&#039;count&#039; =&gt; &#039;6&#039;, &#039;display&#039; =&gt; &#039;latest&#039;, &#039;source&#039; =&gt; &#039;user&#039;, &#039;size&#039; =&gt; &#039;t&#039;, &#039;user&#039; =&gt; &#039;&#039;, &#039;layout&#039; =&gt; &#039;x&#039;, &#039;tag&#039; =&gt; &#039;&#039;, &#039;group&#039; =&gt; &#039;&#039;, &#039;set&#039; =&gt; &#039;&#039;), $atts); 

 	return sprintf(&#039;&lt;div class=&quot;flickr_badge&quot;&gt;&lt;script src=&quot;http://www.flickr.com/badge_code_v2.gne?%s&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;&lt;/div&gt;
&#039;, http_build_query($query_atts));
}

add_shortcode(&#039;flickrbadge&#039;, &#039;flickr_badge_shortcode&#039;);
</pre>
<p>Provided you have PHP5 on the server, <strong>http_build_query()</strong> is the quick and easy way of building a query string from an array &#8211; and it&#8217;s urlencoded&#8230;.</p>
<p>Note that the empty parameters group, set etc. are required in the defaults &#8211; otherwise nothing gets passed to the constructed url via shortcode_atts().</p>
<p>So now, in a post content you can apply the shortcode tag:</p>
<p><strong>[flickrbadge count="4" layout="h" display="latest" size="t" source="all_tag" tag="fish"]</strong></p>
<p>And you should get a nice gallery of Flickr images for users to check out &#8211; once you&#8217;ve added some CSS to style the images (note the possible uses of the layout parameter here).</p>
<p>This example was of the selfclosing shortcode tag &#8211; but you can elaborate a bit, to inject more content into the shortcode function. The simplest example would be to give the gallery a custom title.</p>
<p>Again in functions.php</p>
<pre class="brush: php">

function flickr_badge_shortcode($atts, $content=NULL){

//Here&#039;s our defaults
$query_atts = shortcode_atts(array(&#039;count&#039; =&gt; &#039;6&#039;, &#039;display&#039; =&gt; &#039;latest&#039;, &#039;source&#039; =&gt; &#039;user&#039;, &#039;size&#039; =&gt; &#039;t&#039;, &#039;user&#039; =&gt; &#039;&#039;, &#039;layout&#039; =&gt; &#039;x&#039;, &#039;tag&#039; =&gt; &#039;&#039;, &#039;group&#039; =&gt; &#039;&#039;, &#039;set&#039; =&gt; &#039;&#039;), $atts);

return sprintf(&#039;&lt;div class=&quot;flickr_badge&quot;&gt;&lt;h3&gt;%s&lt;/h3&gt;&lt;script src=&quot;http://www.flickr.com/badge_code_v2.gne?%s&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;&lt;/div&gt;&#039;, $content, http_build_query($query_atts));
}

add_shortcode(&#039;flickrbadge&#039;, &#039;flickr_badge_shortcode&#039;);
</pre>
<p>And would be called from the post content with opening and closing shortcode tags:</p>
<p><strong>[flickrbadge count="4" layout="h" display="latest" size="t" source="all_tag" tag="fish"]Here&#8217;s the latest fish[/flickrbadge]</strong></p>
<p><strong>Caution!</strong><br />
Best to avoid camelCase notation in the attributes &#8211; the regex that the content is passed through to locate shortcodes  is case-insensitive.<br />
Always remember to use <strong>return</strong> in the handler function and not <strong>echo</strong>  (in this example sprintf, not printf). It&#8217;ll appear on the page &#8211; but not in the right place&#8230;</p>
<p>WordPress shortcodes are relatively simple in concept, but can be a bit fiddly in practice, keeping track of the default parameters and the use of  shortcode_atts() just needs a bit of thinking about sometimes&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://themocracy.com/2010/03/a-flickr-badge-using-wordpress-shortcodes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

