<?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>Illuminati Karate, Inc. &#187; Web Development</title>
	<atom:link href="http://illuminatikarate.com/blog/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://illuminatikarate.com</link>
	<description>creative web design, development and marketing</description>
	<lastBuildDate>Wed, 16 May 2012 23:38:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to Add Custom Fields to Media in WordPress</title>
		<link>http://illuminatikarate.com/blog/how-to-add-custom-fields-to-media-in-wordpress/</link>
		<comments>http://illuminatikarate.com/blog/how-to-add-custom-fields-to-media-in-wordpress/#comments</comments>
		<pubDate>Fri, 13 Apr 2012 00:03:32 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress functions]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=781</guid>
		<description><![CDATA[Sometimes a WordPress project calls for custom fields on Media. We recently built a custom gallery widget that involved uploading multiple images that would have a caption, a heading, the ability to selectively output the image, and the ability to set the hex code color of the text that [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes a WordPress project calls for custom fields on Media.  We recently built a custom gallery widget that involved uploading multiple images that would have a caption, a heading, the ability to selectively output the image, and the ability to set the hex code color of the text that was output.</p>
<p>To achieve this, I created a custom field on images that would allow you to input a value to be used as the color for the text and a custom checkbox to indicate to output the image.</p>
<p>There are two steps to this:</p>
<ol>
<li>Add the custom field to the edit screen,</li>
<li>Process that field when saving / updating the media item.</li>
</ol>
<p><span id="more-781"></span></p>
<p>All of the following code can go into functions.php in your theme&#8217;s directory.</p>
<p><strong>Step 1: Adding the Custom Fields to the Edit Screen.</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p781code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7814"><td class="code" id="p781code4"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> ik_image_attachment_fields_to_edit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form_fields</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//we use this variable to set whether or not the checkbox is currently checked</span>
	<span style="color: #666666; font-style: italic;">//defaults to not being checked</span>
	<span style="color: #000088;">$checked</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;_ik_is_hero&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;CHECKED&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//to add a field to the form, there are a few values to set here</span>
	<span style="color: #666666; font-style: italic;">//label: the label of the field being output</span>
	<span style="color: #666666; font-style: italic;">//input: the type of input being output - can use 'html' as value for more custom control</span>
	<span style="color: #666666; font-style: italic;">//value: the current value of the input</span>
	<span style="color: #666666; font-style: italic;">//helps: the descriptive text shown below the field</span>
	<span style="color: #666666; font-style: italic;">//html: the custom html to use for a field if input is set to 'html' (see: 'ik_is_hero')</span>
	<span style="color: #000088;">$form_fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ik_text_color&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">&quot;label&quot;</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Custom Text Color&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;input&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// this is default if &quot;input&quot; is omitted</span>
		<span style="color: #0000ff;">&quot;value&quot;</span> <span style="color: #339933;">=&gt;</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;_ik_text_color&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">&quot;helps&quot;</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Expects a hex code.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$form_fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ik_is_hero&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">&quot;label&quot;</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Show In Hero Widget&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'input'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'html'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'html'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&lt;input type='checkbox'
				name='attachments[<span style="color: #006699; font-weight: bold;">{$post-&gt;ID}</span>][ik_is_hero]'
				id='attachments[<span style="color: #006699; font-weight: bold;">{$post-&gt;ID}</span>][ik_is_hero]'
                		value='1' <span style="color: #006699; font-weight: bold;">{$checked}</span>/&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;helps&quot;</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;If checked, this image will show in the widget.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$form_fields</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// now attach our function to the hook</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;attachment_fields_to_edit&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ik_image_attachment_fields_to_edit&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>An important note for when using the html input type:</strong> be sure to follow this convention for the name and id of your input &#8211; <code>'attachments[the attachment id][the custom field slug]'</code>. Otherwise you&#8217;ll have trouble saving the fields with the code below.</p>
<p><strong>Step 2: Updating the Custom Fields on Save.</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p781code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7815"><td class="code" id="p781code5"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> ik_image_attachment_fields_to_save<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attachment</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//for the standard input, we check to see if it's set and, if so, save it</span>
	<span style="color: #666666; font-style: italic;">//if you want to modify or sanitize the data, now is the time to do so</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ik_text_color'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_ik_text_color'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ik_text_color'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">//for the checkbox we save the value if it's currently checked</span>
	<span style="color: #666666; font-style: italic;">//if it's not checked there won't be a value set, so we set it to '0'</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ik_is_hero'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_ik_is_hero'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attachment</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ik_is_hero'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_ik_is_hero'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// now attach our function to the hook</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;attachment_fields_to_save&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ik_image_attachment_fields_to_save&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Don&#8217;t forget to use the fields!</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p781code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7816"><td class="code" id="p781code6"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//load the data (assuming you've already loaded the media, in this case post attachments)</span>
<span style="color: #000088;">$is_checked</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;_ik_is_hero&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$text_color</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;_ik_text_color&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//now you can do whatever you want!</span></pre></td></tr></table></div>

<p>I hope this is helpful!  Feel free to ask questions in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/how-to-add-custom-fields-to-media-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress: How to Exclude Categories From the Archive Widget</title>
		<link>http://illuminatikarate.com/blog/wordpress-how-to-exclude-categories-from-the-archive-widget/</link>
		<comments>http://illuminatikarate.com/blog/wordpress-how-to-exclude-categories-from-the-archive-widget/#comments</comments>
		<pubDate>Tue, 27 Mar 2012 20:28:34 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress functions]]></category>
		<category><![CDATA[custom wordpress widgets]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=785</guid>
		<description><![CDATA[Updated: 5/2/2012 We love developing in WordPress. For many of our clients, there is no need to reinvent the wheel and WordPress can be a significant time saver. WordPress is a very thoroughly developed platform &#8211; yet every now and again we bump into desired functionality that isn&#8217;t readily [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em>Updated: 5/2/2012</em></p>
<p>We love developing in WordPress. For many of our clients, there is no need to reinvent the wheel and WordPress can be a significant time saver.</p>
<p>WordPress is a very thoroughly developed platform &#8211; yet every now and again we bump into desired functionality that isn&#8217;t readily available, such as excluding categories from the Archive Widget.</p>
<p>Recently, I developed some code to do just that and thought I would share it.<br />
<span id="more-785"></span></p>
<p><em>If you want to know how to include categories, instead of excluding them, <a href="http://illuminatikarate.com/blog/wordpress-how-to-exclude-categories-from-the-archive-widget/#comment-18028">read my reply</a> to Ian&#8217;s comment below.</em></p>
<p>The default Archives Widget gives you just a few options: you can set the title, use a drop-down or a list, and display the post count next to the month.  You get more functionality if you use the <a href="http://codex.wordpress.org/Function_Reference/wp_get_archives" target="_blank">wp_get_archives()</a> function, but that won&#8217;t always get you what you need (and sometimes you <em>really</em> want to use a widget).</p>
<p>After spending some time poking around in general-template.php (/wp-includes/general-template.php), I found what I was looking for around lines 918-919: two filters, &#8216;getarchives_where&#8217; and &#8216;getarchives_join&#8217;.  These filters are applied to the SQL right before the Archives query is run, so they are the ideal point to do any heavy customization to the data that is displayed there.</p>
<p>What each of them does is pretty self-explanatory; getarchives_where modifies the WHERE clause of the SQL query and getarchives_join modifies the JOIN clause of the SQL query.  Arm yourself with a bit of knowledge as to how WordPress works and these become some powerful tools.</p>
<p><strong>On to the code&#8230;</strong></p>
<p>Here are two functions that will update the SQL as desired:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p785code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p78511"><td class="code" id="p785code11"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//add custom SQL to the archives widget JOIN clause</span>
<span style="color: #000000; font-weight: bold;">function</span> ik_custom_archives_join<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;LEFT JOIN <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_relationships</span> ON(<span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span>.ID = <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_relationships</span>.object_id) &quot;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;LEFT JOIN <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_taxonomy</span> ON(<span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_relationships</span>.term_taxonomy_id = <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_taxonomy</span>.term_taxonomy_id) &quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$sql</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The above code will join in the Category information, to be used for excluding the desired Categories in the following code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p785code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p78512"><td class="code" id="p785code12"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//add custom SQL to the archives widget WHERE clause</span>
<span style="color: #000000; font-weight: bold;">function</span> ik_custom_archives_where<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//get categories IDs from slugs</span>
	<span style="color: #000088;">$exclude_cat_1</span> <span style="color: #339933;">=</span> get_category_by_slug<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;exclude-cat-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$exclude_cat_2</span> <span style="color: #339933;">=</span> get_category_by_slug<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;exclude-cat-2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//list of categories to exclude</span>
	<span style="color: #000088;">$exclude_list</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exclude_cat_1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cat_ID</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">', '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$exclude_cat_2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cat_ID</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;WHERE post_type = 'post' AND post_status = 'publish' &quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;AND <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_taxonomy</span>.term_id NOT IN (<span style="color: #006699; font-weight: bold;">$exclude_list</span>)&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$sql</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The above code does a couple of things:</p>
<ol>
<li>Loads the category data by slug (recommended as it&#8217;s hard to predict IDs)</li>
<li>Modifies the WHERE clause to exclude those Categories</li>
</ol>
<p>With those 2 functions in hand, you just need to add the filters to your theme&#8217;s functions.php file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p785code13'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p78513"><td class="code" id="p785code13"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//add the ik archive filters</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'getarchives_where'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'ik_custom_archives_where'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'getarchives_join'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'ik_custom_archives_join'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And that&#8217;s it!  A simple solution to exclude certain categories from the default Archives widget.</p>
<p>If you know a bit of SQL you can also use this code to make other modifications to the Archives widget, such as custom date ranges, excluding or including custom post types, and more.</p>
<p><strong>Here&#8217;s the full code:</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p785code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p78514"><td class="code" id="p785code14"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//add the ik archive filters</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'getarchives_where'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'ik_custom_archives_where'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'getarchives_join'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'ik_custom_archives_join'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//add custom SQL to the archives widget JOIN clause</span>
<span style="color: #000000; font-weight: bold;">function</span> ik_custom_archives_join<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;LEFT JOIN <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_relationships</span> ON(<span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span>.ID = <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_relationships</span>.object_id) &quot;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;LEFT JOIN <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_taxonomy</span> ON(<span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_relationships</span>.term_taxonomy_id = <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_taxonomy</span>.term_taxonomy_id) &quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$sql</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//add custom SQL to the archives widget WHERE clause</span>
<span style="color: #000000; font-weight: bold;">function</span> ik_custom_archives_where<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//get categories IDs from slugs</span>
	<span style="color: #000088;">$exclude_cat_1</span> <span style="color: #339933;">=</span> get_category_by_slug<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;exclude-cat-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$exclude_cat_2</span> <span style="color: #339933;">=</span> get_category_by_slug<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;exclude-cat-2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//list of categories to exclude</span>
	<span style="color: #000088;">$exclude_list</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exclude_cat_1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cat_ID</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">', '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$exclude_cat_2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cat_ID</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;WHERE post_type = 'post' AND post_status = 'publish' &quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sql</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;AND <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_taxonomy</span>.term_id NOT IN (<span style="color: #006699; font-weight: bold;">$exclude_list</span>)&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$sql</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/wordpress-how-to-exclude-categories-from-the-archive-widget/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Display Recent Spotify Track with Album Cover using PHP</title>
		<link>http://illuminatikarate.com/blog/display-recent-spotify-track-with-album-cover-using-php/</link>
		<comments>http://illuminatikarate.com/blog/display-recent-spotify-track-with-album-cover-using-php/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 04:32:29 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[custom functions]]></category>
		<category><![CDATA[spotify]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=731</guid>
		<description><![CDATA[Many of our clients show their personalities on their websites &#8211; from Facebook to Twitter feeds, photo streams and more, they like to integrate a bit of themselves. While hooking up a Social Media feed is no problem, recently we had a unique request to develop a widget that [...]]]></description>
			<content:encoded><![CDATA[<p>Many of our clients show their personalities on their websites &#8211; from Facebook to Twitter feeds, photo streams and more, they like to integrate a bit of themselves.  While hooking up a Social Media feed is no problem, recently we had a unique request to develop a widget that displays the most recently listened to Spotify track with artist information and album cover.</p>
<p>It turns out there isn&#8217;t a straightforward way to do this; after a little digging around on the internet, and the help of the Spotify API, we were able to put together a solution that I wanted to share.</p>
<p><strong>There are several steps to this process:</strong></p>
<ol>
<li>Create a <a href="http://www.last.fm/" title="Lastfm" target="_blank">Lastfm </a>account and setup <a href="http://www.spotify.com" target="_blank">Spotify</a> to scrobble to Last.fm</li>
<li>Pull the Lastfm Recent Tracks RSS feed</li>
<li>Look-up the desired Track using the <a href="http://developer.spotify.com/en/metadata-api/overview/" target="_blank">Spotify Metadata API</a> and load the data</li>
</ol>
<p><span id="more-731"></span><br />
First, we need a basic cURL function:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p731code19'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p73119"><td class="code" id="p731code19"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_init"><span style="color: #990000;">curl_init</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$retData</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_exec"><span style="color: #990000;">curl_exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_close"><span style="color: #990000;">curl_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$retData</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>With that in hand, it&#8217;s time to get down to business. </p>
<p>We start by loading the Last.fm RSS feed to get the latest track:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p731code20'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p73120"><td class="code" id="p731code20"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> loadSpotifyTracks<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$lastfm_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ws.audioscrobbler.com/2.0/user/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/recenttracks.rss&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$trackAttributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lastfm_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/simplexml_load_string"><span style="color: #990000;">simplexml_load_string</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$count</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pubDate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubDate</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pubDate_time</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strtotime"><span style="color: #990000;">strtotime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pubDate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//format is Artist - Track</span>
		<span style="color: #000088;">$artistData</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; – &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//get track album cover and info</span>
		<span style="color: #000088;">$trackAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> getTrackAttributes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$artistData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$artistData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$trackAttributes</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The above function will load the Most Recent RSS Feed of the Lastfm account passed, and will loop through <code>$count</code> of them, loading the attributes.  </p>
<p>You need to include the following function to be able to load the attributes from Spotify:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p731code21'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p73121"><td class="code" id="p731code21"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//get attributes of track from Spotify</span>
<span style="color: #000000; font-weight: bold;">function</span> getTrackAttributes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$artistname</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	
	<span style="color: #666666; font-style: italic;">//default return data</span>
	<span style="color: #000088;">$retData</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'artist'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'cover'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'album'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'trackUrl'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//search spotify, find match by artist and trackname, then pull that data</span>
	<span style="color: #000088;">$first_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://ws.spotify.com/search/1/track?q='</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$first_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
	<span style="color: #000088;">$xmlObjs</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/simplexml_load_string"><span style="color: #990000;">simplexml_load_string</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlObjs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlObjs</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$xmlObj</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//check to see if the Track and Album name both match,</span>
			<span style="color: #666666; font-style: italic;">//if they do, use the data</span>
			<span style="color: #666666; font-style: italic;">//there's many ways to do this, this is quick and dirty version</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlObj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackname</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlObj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">artist</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$artistname</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$albumName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$trackURL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$albumName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xmlObj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">album</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$trackURL</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xmlObj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/end"><span style="color: #990000;">end</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$trackURL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$trackURL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://open.spotify.com/track/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$uri</span><span style="color: #339933;">;</span>				
				<span style="color: #000088;">$coverResults</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackURL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//load album cover info from track</span>
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$coverResults</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$parser</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/xml_parser_create"><span style="color: #990000;">xml_parser_create</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$vals</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$index</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<a href="http://www.php.net/xml_parse_into_struct"><span style="color: #990000;">xml_parse_into_struct</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$coverResults</span><span style="color: #339933;">,</span> <span style="color: #000088;">$vals</span><span style="color: #339933;">,</span> <span style="color: #000088;">$index</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<a href="http://www.php.net/xml_parser_free"><span style="color: #990000;">xml_parser_free</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$vals</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$vals</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
							<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'META'</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attributes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PROPERTY'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">14</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'og:image'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
								<span style="color: #000088;">$coverImage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attributes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'CONTENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
							<span style="color: #009900;">&#125;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">//we want the fullsized image, not the thumbnail</span>
				<span style="color: #000088;">$coverImage</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumb'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$coverImage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
				<span style="color: #666666; font-style: italic;">//no image? use the default data</span>
				<span style="color: #666666; font-style: italic;">//you can remove this check if you're ok not having an album cover</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$coverImage</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">//has cover image, use the returned data</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$trackname</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'artist'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$artistname</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cover'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$coverImage</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'album'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$albumName</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trackUrl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$trackURL</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>		
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$retData</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here&#8217;s what that wall-of-text does:</p>
<ul>
<li>Searches for the Track using the Spotify API</li>
<li>If a matching track/album is found, generates a Track URL from the match&#8217;s URI</li>
<li>Loads that track&#8217;s info from the Spotify API and grabs the image from the result</li>
</ul>
<p><strong>A few notes:</strong></p>
<ol>
<li>You will want to cache your requests.  It&#8217;s polite (and they&#8217;ll probably cut you off, otherwise).</li>
<li>You&#8217;ll probably want some fallback display data.  Sometimes an exact match isn&#8217;t found.  The above code isn&#8217;t perfect.</li>
<li>You might want to think about loading this via AJAX &#8211; the page can hang a second while waiting for the info to load.</li>
</ol>
<p><strong>Here is the complete code, in one box:</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p731code22'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p73122"><td class="code" id="p731code22"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_init"><span style="color: #990000;">curl_init</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$retData</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_exec"><span style="color: #990000;">curl_exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_close"><span style="color: #990000;">curl_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$retData</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//get attributes of track from Spotify</span>
<span style="color: #000000; font-weight: bold;">function</span> getTrackAttributes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$artistname</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	
	<span style="color: #666666; font-style: italic;">//default return data</span>
	<span style="color: #000088;">$retData</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'artist'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'cover'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'album'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'trackUrl'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&quot;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//search spotify, find match by artist and trackname, then pull that data</span>
	<span style="color: #000088;">$first_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://ws.spotify.com/search/1/track?q='</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$first_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
	<span style="color: #000088;">$xmlObjs</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/simplexml_load_string"><span style="color: #990000;">simplexml_load_string</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlObjs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlObjs</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$xmlObj</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//check to see if the Track and Album name both match,</span>
			<span style="color: #666666; font-style: italic;">//if they do, use the data</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlObj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackname</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlObj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">artist</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$artistname</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$albumName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$trackURL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$albumName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xmlObj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">album</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$trackURL</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xmlObj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/end"><span style="color: #990000;">end</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$trackURL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$trackURL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://open.spotify.com/track/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$uri</span><span style="color: #339933;">;</span>				
				<span style="color: #000088;">$coverResults</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackURL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//load album cover info from track</span>
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$coverResults</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$parser</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/xml_parser_create"><span style="color: #990000;">xml_parser_create</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$vals</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$index</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<a href="http://www.php.net/xml_parse_into_struct"><span style="color: #990000;">xml_parse_into_struct</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$coverResults</span><span style="color: #339933;">,</span> <span style="color: #000088;">$vals</span><span style="color: #339933;">,</span> <span style="color: #000088;">$index</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<a href="http://www.php.net/xml_parser_free"><span style="color: #990000;">xml_parser_free</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$vals</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$vals</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
							<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'META'</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attributes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PROPERTY'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">14</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'og:image'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
								<span style="color: #000088;">$coverImage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attributes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'CONTENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
							<span style="color: #009900;">&#125;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">//we want the fullsized image, not the thumbnail</span>
				<span style="color: #000088;">$coverImage</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumb'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$coverImage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
				<span style="color: #666666; font-style: italic;">//no image? use the default data</span>
				<span style="color: #666666; font-style: italic;">//you can remove this check if you're ok not having an album cover</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$coverImage</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">//has cover image, use the returned data</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$trackname</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'artist'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$artistname</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cover'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$coverImage</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'album'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$albumName</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$retData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trackUrl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$trackURL</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>		
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$retData</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//load Spotify Tracks</span>
<span style="color: #000000; font-weight: bold;">function</span> loadSpotifyTracks<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$lastfm_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ws.audioscrobbler.com/2.0/user/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/recenttracks.rss&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$trackAttributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lastfm_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/simplexml_load_string"><span style="color: #990000;">simplexml_load_string</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rss</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$count</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pubDate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pubDate</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pubDate_time</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strtotime"><span style="color: #990000;">strtotime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pubDate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//format is Artist - Track</span>
		<span style="color: #000088;">$artistData</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; – &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//get track album cover and info</span>
		<span style="color: #000088;">$trackAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> getTrackAttributes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$artistData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$artistData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$trackAttributes</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//do something!</span>
<span style="color: #000088;">$trackAttributes</span> <span style="color: #339933;">=</span> loadSpotify<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//only output data if a match is found</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trackAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trackUrl'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$trackAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trackUrl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$trackAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cover'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; /&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;div class=&quot;info&quot;&gt;
			&lt;span class=&quot;title&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$trackAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/span&gt;
			&lt;span class=&quot;artist&quot;&gt;by '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$trackAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'artist'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/span&gt;
			&lt;span class=&quot;album&quot;&gt;on '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$trackAttributes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'album'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/span&gt;
		&lt;/div&gt;&lt;/a&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And that&#8217;s it!  A solution to display recent Spotify track with album cover using PHP.</p>
<p>I hope you find it helpful!</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/display-recent-spotify-track-with-album-cover-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress: Only Show Authors Their Own Posts and Media in the Admin Area</title>
		<link>http://illuminatikarate.com/blog/wordpress-only-show-authors-their-own-posts-and-media-in-the-admin-area/</link>
		<comments>http://illuminatikarate.com/blog/wordpress-only-show-authors-their-own-posts-and-media-in-the-admin-area/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 01:45:08 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress functions]]></category>
		<category><![CDATA[membership sites]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=665</guid>
		<description><![CDATA[Updated: 5/13/2012 I&#8217;ve helped our clients set up a lot of membership sites; one common request is that members are able to submit articles within WordPress. Out-of-the-box WordPress can get you pretty far but commonly I run into two roadblocks with the default roles: The Contributor role doesn&#8217;t let [...]]]></description>
			<content:encoded><![CDATA[<p><em>
<p style="text-align: center;">Updated: 5/13/2012</p>
<p></em></p>
<p>I&#8217;ve helped our clients set up a lot of membership sites; one common request is that members are able to submit articles within WordPress.</p>
<p>Out-of-the-box WordPress can get you pretty far but commonly I run into two roadblocks with the default roles:</p>
<ol>
<li>The Contributor role doesn&#8217;t let Contributors see the Media Library</li>
<li>The Author role lets Authors see <em>everyone&#8217;s</em> Media &amp; Posts</li>
</ol>
<p>While more often than not a plugin is the way to go for a full-on membership site, there&#8217;s a really quick fix that will let you assign users to the Author role and be able to hide other&#8217;s Media &amp; Posts from them.<br />
<span id="more-665"></span></p>
<p><em>Edit: Per Winston Small&#8217;s comment below, in WordPress 3.2.1 you have to change &#8216;/wp-admin/upload.php&#8217; to &#8216;/wp-admin/media-upload.php&#8217;.</em></p>
<p>Paste the following code into your theme&#8217;s functions.php file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p665code25'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66525"><td class="code" id="p665code25"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//restrict authors to only being able to view media that they've uploaded</span>
<span style="color: #000000; font-weight: bold;">function</span> ik_eyes_only<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wp_query</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//are we looking at the Media Library or the Posts list?</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/strpos"><span style="color: #990000;">strpos</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">'REQUEST_URI'</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/wp-admin/upload.php'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span>  
	<span style="color: #339933;">||</span> <a href="http://www.php.net/strpos"><span style="color: #990000;">strpos</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">'REQUEST_URI'</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/wp-admin/edit.php'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//user level 5 converts to Editor</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>current_user_can<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'level_5'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//restrict the query to current user</span>
			<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$current_user</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'author'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current_user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p665code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66526"><td class="code" id="p665code26"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//filter media library &amp; posts list for authors</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parse_query'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ik_eyes_only'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The above code will check to see if you are viewing the Media Library or the Posts section of the WordPress admin.  If you are, it then checks to see if you are at Level 5 or above (e.g: Editor or Administrator).  If you aren&#8217;t either of those two then it modifies the query to only include items authored by the current user.</p>
<p>With that code in place you just need to add it to the parse_query filter and you&#8217;re off to the races!</p>
<p>I hope this is helpful!  Ask any questions in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/wordpress-only-show-authors-their-own-posts-and-media-in-the-admin-area/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>How To Add A Lightbox To A WordPress Gallery</title>
		<link>http://illuminatikarate.com/blog/wordpress-how-to-add-a-lightbox-to-a-wordpress-gallery/</link>
		<comments>http://illuminatikarate.com/blog/wordpress-how-to-add-a-lightbox-to-a-wordpress-gallery/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 14:39:25 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress functions]]></category>
		<category><![CDATA[prettyphoto]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=532</guid>
		<description><![CDATA[Updated: 2/29/12 I wanted to setup a simple lightbox photo gallery on a WordPress site (v3.2.1, tested and working on 3.3.1) and, to avoid installing a slew of plugins, I put together a little gallery shortcode function using the built-in WordPress gallery shortcode as my starting point. I&#8217;m a [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align:center;"><em>Updated: 2/29/12</em></p>
<p>I wanted to setup a simple lightbox photo gallery on a WordPress site (v3.2.1, tested and working on 3.3.1) and, to avoid installing a slew of plugins, I put together a little gallery shortcode function using the built-in WordPress gallery shortcode as my starting point. I&#8217;m a big fan of <a title="PrettyPhoto" href="http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/" target="_blank">PrettyPhoto</a>, so I modified the output of the gallery shortcode to include a rel= attribute for PrettyPhoto galleries.<span id="more-532"></span></p>
<p>I grabbed the standard WordPress gallery shortcode from line ~758 in wp-includes/media.php and pasted it into my_theme/functions.php for modification.  For the more adventurous folks you can override the default WordPress gallery shortcode and then galleries you&#8217;ve inserted using the Media Gallery will be lightboxed.</p>
<p>This also gives you a good entry point for making other modifications to the standard gallery output.</p>
<p>Here&#8217;s the code I ended up with in functions.php <em>(shortened for readability, you&#8217;ll want to copy and past the entire block of code below this into your functions.php file)</em>:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code32'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p53232"><td class="code" id="p532code32"><pre class="php" style="font-family:monospace;">add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_gallery_shortcode'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_gallery_shortcode_function'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_gallery_shortcode_function<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$attachments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attachment</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">'file'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span> ? wp_get_attachment_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> wp_get_attachment_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//add rel=&quot;prettyPhoto[pp_gal]&quot;</span>
		<span style="color: #666666; font-style: italic;">//this is my edit</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&gt;&lt;img'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'rel=&quot;prettyPhoto[pp_gal]&quot; &gt;&lt;img'</span><span style="color: #339933;">,</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;<span style="color: #006699; font-weight: bold;">{$itemtag}</span> class='gallery-item'&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
			&lt;<span style="color: #006699; font-weight: bold;">{$icontag}</span> class='gallery-icon'&gt;
				<span style="color: #006699; font-weight: bold;">$link</span>
			&lt;/<span style="color: #006699; font-weight: bold;">{$icontag}</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$captiontag</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_excerpt</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
				&lt;<span style="color: #006699; font-weight: bold;">{$captiontag}</span> class='wp-caption-text gallery-caption'&gt;
				&quot;</span> <span style="color: #339933;">.</span> wptexturize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_excerpt</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;
				&lt;/<span style="color: #006699; font-weight: bold;">{$captiontag}</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/<span style="color: #006699; font-weight: bold;">{$itemtag}</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$columns</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$columns</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;br style=&quot;clear: both&quot; /&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
			&lt;br style='clear: both;' /&gt;
		&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>My edit was small, I added <code>$link=str_replace('&gt;&lt;img','rel="prettyPhoto[pp_gal]" &gt;&lt;img',$link);</code> to the gallery output so that PrettyPhoto can do it&#8217;s thing.</p>
<p>Here is the full code to copy and paste into your functions.php file:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code33'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p53233"><td class="code" id="p532code33"><pre class="php" style="font-family:monospace;">add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_gallery_shortcode'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_gallery_shortcode_function'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_gallery_shortcode_function<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_locale</span><span style="color: #339933;">;</span>
&nbsp;
	static <span style="color: #000088;">$instance</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$instance</span><span style="color: #339933;">++;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Allow plugins/themes to override the default gallery template.</span>
	<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_gallery'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$output</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// We're trusting author input, so let's at least make sure it looks like a valid orderby statement</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'orderby'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'orderby'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> sanitize_sql_orderby<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'orderby'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'orderby'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
			<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'orderby'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<a href="http://www.php.net/extract"><span style="color: #990000;">extract</span></a><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'order'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ASC'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'orderby'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu_order ID'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'id'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'itemtag'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dl'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'icontag'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dt'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'captiontag'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dd'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'columns'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'size'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'thumbnail'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'include'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'exclude'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'RAND'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$order</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$orderby</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'none'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$include</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$include</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'/[^0-9,]+/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$include</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$_attachments</span> <span style="color: #339933;">=</span> get_posts<span style="color: #009900;">&#40;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$include</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'inherit'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'attachment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_mime_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'image'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$order</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'orderby'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$orderby</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$attachments</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_attachments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$attachments</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_attachments</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$exclude</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$exclude</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'/[^0-9,]+/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$exclude</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$attachments</span> <span style="color: #339933;">=</span> get_children<span style="color: #009900;">&#40;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_parent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'exclude'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$exclude</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'inherit'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'attachment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_mime_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'image'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$order</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'orderby'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$orderby</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$attachments</span> <span style="color: #339933;">=</span> get_children<span style="color: #009900;">&#40;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_parent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'inherit'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'attachment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_mime_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'image'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$order</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'orderby'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$orderby</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachments</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$attachments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$att_id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attachment</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> wp_get_attachment_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$att_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$itemtag</span> <span style="color: #339933;">=</span> tag_escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$itemtag</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$captiontag</span> <span style="color: #339933;">=</span> tag_escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$captiontag</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$columns</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$itemwidth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$columns</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> ? <a href="http://www.php.net/floor"><span style="color: #990000;">floor</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">/</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$float</span> <span style="color: #339933;">=</span> is_rtl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'right'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'left'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$selector</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;gallery-<span style="color: #006699; font-weight: bold;">{$instance}</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$gallery_style</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gallery_div</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'use_default_gallery_style'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$gallery_style</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
		&lt;style type='text/css'&gt;
			#<span style="color: #006699; font-weight: bold;">{$selector}</span> {
				margin: auto;
			}
			#<span style="color: #006699; font-weight: bold;">{$selector}</span> .gallery-item {
				float: <span style="color: #006699; font-weight: bold;">{$float}</span>;
				margin-top: 10px;
				text-align: center;
				width: <span style="color: #006699; font-weight: bold;">{$itemwidth}</span>%;
			}
			#<span style="color: #006699; font-weight: bold;">{$selector}</span> img {
				border: 2px solid #cfcfcf;
			}
			#<span style="color: #006699; font-weight: bold;">{$selector}</span> .gallery-caption {
				margin-left: 0;
			}
		&lt;/style&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$size_class</span> <span style="color: #339933;">=</span> sanitize_html_class<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$size</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$gallery_div</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;div id='<span style="color: #006699; font-weight: bold;">$selector</span>' class='gallery galleryid-<span style="color: #006699; font-weight: bold;">{$id}</span> gallery-columns-<span style="color: #006699; font-weight: bold;">{$columns}</span> gallery-size-<span style="color: #006699; font-weight: bold;">{$size_class}</span>'&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'gallery_style'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$gallery_style</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$gallery_div</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$attachments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attachment</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">'file'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span> ? wp_get_attachment_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> wp_get_attachment_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//add rel=&quot;gal[lightbox]&quot;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;a&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;a rel=<span style="color: #000099; font-weight: bold;">\&quot;</span>gal[lightbox]<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;<span style="color: #006699; font-weight: bold;">{$itemtag}</span> class='gallery-item'&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
			&lt;<span style="color: #006699; font-weight: bold;">{$icontag}</span> class='gallery-icon'&gt;
				<span style="color: #006699; font-weight: bold;">$link</span>
			&lt;/<span style="color: #006699; font-weight: bold;">{$icontag}</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$captiontag</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_excerpt</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
				&lt;<span style="color: #006699; font-weight: bold;">{$captiontag}</span> class='wp-caption-text gallery-caption'&gt;
				&quot;</span> <span style="color: #339933;">.</span> wptexturize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_excerpt</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;
				&lt;/<span style="color: #006699; font-weight: bold;">{$captiontag}</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/<span style="color: #006699; font-weight: bold;">{$itemtag}</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$columns</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$columns</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;br style=&quot;clear: both&quot; /&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
			&lt;br style='clear: both;' /&gt;
		&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now that you have that all you need to do is be sure you&#8217;re including the necessary files:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code34'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p53234"><td class="code" id="p532code34"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> media<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;all&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=bloginfo('template_directory');?&gt;/prettyPhoto/css/prettyPhoto.css&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?=bloginfo('template_directory');?&gt;/prettyPhoto/js/jquery.prettyPhoto.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>And be sure to call PrettyPhoto:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code35'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p53235"><td class="code" id="p532code35"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[rel^='prettyPhoto']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prettyPhoto</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Now all you need to do is upload photos to your gallery and use this shortcode on your page:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code36'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p53236"><td class="code" id="p532code36"><pre class="html" style="font-family:monospace;">[my_gallery_shortcode link=&quot;file&quot;]</pre></td></tr></table></div>

<p>And that&#8217;s it!  A quick solution to adding a lightbox to your WordPress gallery.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/wordpress-how-to-add-a-lightbox-to-a-wordpress-gallery/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>WordPress: How To Change Comment Excerpt Length</title>
		<link>http://illuminatikarate.com/blog/wordpress-how-to-change-comment-excerpt-length/</link>
		<comments>http://illuminatikarate.com/blog/wordpress-how-to-change-comment-excerpt-length/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 18:17:17 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=493</guid>
		<description><![CDATA[I recently needed to output a list of comments and bumped into a little trouble trying to output the comment excerpt. Usually I would use the built-in comment_excerpt() function but I only needed 10 words instead of the 20 that is hard-coded. I put together a little function that [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to output a list of comments and bumped into a little trouble trying to output the comment excerpt.  Usually I would use the built-in comment_excerpt() function but I only needed 10 words instead of the 20 that is hard-coded.  I put together a little function that I found helpful and thought I would share.</p>
<p>  <span id="more-493"></span></p>
<p>I started with get_comment_excerpt() from line ~407 of wp-includes/comment-template.php and pasted it into my_name/functions.php to be modified.</p>
<p>Here&#8217;s what I ended up with:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p493code39'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49339"><td class="code" id="p493code39"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_get_comment_excerpt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_ID</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num_words</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$comment</span> <span style="color: #339933;">=</span> get_comment<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$comment_ID</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$comment_text</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strip_tags"><span style="color: #990000;">strip_tags</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$blah</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$comment_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$blah</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$num_words</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$num_words</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$use_dotdotdot</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$blah</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$use_dotdotdot</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$excerpt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$k</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$excerpt</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$blah</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$excerpt</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$use_dotdotdot</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'...'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get_comment_excerpt'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$excerpt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><br/></p>
<p>And here&#8217;s a little code to output a list of comments using this function:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p493code40'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p49340"><td class="code" id="p493code40"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
	<span style="color: #000088;">$comments</span> <span style="color: #339933;">=</span> get_comments<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo get_permalink(<span style="color: #006699; font-weight: bold;">$c-&gt;comment_post_ID</span>); ?&gt;&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">/* output 10 words of comment */</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> my_get_comment_excerpt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_ID</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>		
		<span style="color: #339933;">&lt;</span>span<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_author</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>span<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m/j/Y&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/strtotime"><span style="color: #990000;">strtotime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_date</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Feel free to ask questions in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/wordpress-how-to-change-comment-excerpt-length/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WP e-Commerce Category Product List Shortcode</title>
		<link>http://illuminatikarate.com/blog/wp-e-commerce-category-product-list-shortcode/</link>
		<comments>http://illuminatikarate.com/blog/wp-e-commerce-category-product-list-shortcode/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 17:35:59 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress functions]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[WP E-Commerce]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=570</guid>
		<description><![CDATA[Update: tested and working on v3.8.8. While setting up a store using WP e-Commerce I noticed that the Category Product List Shortcode was no longer working for me. I cooked up a quick shortcode function using some of their product list code that will query the products by the [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em>Update: tested and working on v3.8.8.</em></p>
<p>While setting up a store using <a href="http://www.instinct.co.nz/e-commerce/" target="_blank" title="WP E-Commerce">WP e-Commerce</a> I noticed that the <a href="http://www.instinct.co.nz/e-commerce/integration/" target="_blank">Category Product List Shortcode</a> was no longer working for me.  </p>
<p>I cooked up a quick shortcode function using some of their product list code that will query the products by the passed category and output them using the product template.<span id="more-570"></span></p>
<p>First, place the following code in my_theme/functions.php:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p570code42'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57042"><td class="code" id="p570code42"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_wpsc_products_shortcode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$number_per_page</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'use_pagination'</span><span style="color: #009900;">&#41;</span> ? get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpsc_products_per_page'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> shortcode_atts<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'category_id'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$atts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'limit_of_items'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'sort_order'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'number_per_page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$number_per_page</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'page'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> wpsc_display_products_page<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_wpsc_category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_wpsc_products_shortcode'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Once that&#8217;s done you&#8217;ll be able to use <code>[my_wpsc_category cat=6 /]</code>, where 6 is the integer ID of the category, on whichever page you want the products displayed on.  </p>
<p>This list will be output using the wpsc-single_product.php template or the wpsc-products_page.php template, depending on whether you have multiple products in the category.</p>
<p>Feel free to ask questions in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/wp-e-commerce-category-product-list-shortcode/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Finding the Carrier of a Cell Phone Number in PHP</title>
		<link>http://illuminatikarate.com/blog/finding-the-carrier-of-a-cell-phone-number-in-php/</link>
		<comments>http://illuminatikarate.com/blog/finding-the-carrier-of-a-cell-phone-number-in-php/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 03:47:37 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[cell phones]]></category>
		<category><![CDATA[cellular]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=470</guid>
		<description><![CDATA[Often web apps need to send SMS messages to their users (for example: balance alerts, reminders, notifications). To send these text messages from within your app, you basically have 2 options: 1) Pay Twilio and Tropo for the use of their APIs, for roughly a penny per message. 2) [...]]]></description>
			<content:encoded><![CDATA[<p>Often web apps need to send SMS messages to their users (for example: balance alerts, reminders, notifications). To send these text messages from within your app, you basically have 2 options:</p>
<p>1) Pay <a title="Twilio" href="http://twilio.com">Twilio</a> and <a title="Tropo" href="http://tropo.com">Tropo</a> for the use of their APIs, for roughly a penny per message.</p>
<p>2) Send an email directly to their carrier&#8217;s mail-to-SMS gateway &#8211; a free service most carriers provide, which will translate your email into an SMS sent to their subscribers&#8217; phone</p>
<p>Twilio and Tropo are about as easy as it gets to integrate (REST-like APIs that return <a href="http://json.org">JSON</a>/<a href="http://en.wikipedia.org/wiki/Plain_Old_XML">POX</a>), but you pay for every single message and that can add up quickly. So #2 (mail-to-SMS gateways) starts to look pretty good.</p>
<p>But there&#8217;s some problems with mail-to-SMS gateways:<span id="more-470"></span></p>
<p>1) Each carrier has their own format. For example, T-Mobile&#8217;s gateway is <em>number</em>@tmomail.net (for the US), AT&amp;T&#8217;s is <em>number</em>@txt.att.net (for most of their customers), and Verizon is <em>number</em>@vtext.net (unless you used to be with Alltel &#8211; then its <em>number</em>@message.alltel.com). A big <a href="http://en.wikipedia.org/wiki/List_of_SMS_gateways">list of mail-to-SMS-gateways</a> is available on Wikipedia.</p>
<p>Bonus:some carriers want the international code prepended (the 1 in front of  the number, for the US), some carriers don&#8217;t. (e.g., T-Mobile does,  AT&amp;T doesn&#8217;t)</p>
<p>2) Some carriers require authentication (Sprint) or don&#8217;t have a mail-to-SMS gateway at all (Google Voice).</p>
<p>3) If the user ports their number to a different carrier you&#8217;ll have to detect it and react accordingly.</p>
<p>So you&#8217;ll have to figure out what carrier they&#8217;re using in order to direct the email and meet whatever requirements &#8211; which usually means asking the user to choose their carrier from a list.</p>
<p><strong>There is a better way!</strong> What if we could detect the carrier automatically?</p>
<p>It turns out you can. The lovely folks at <a href="http://cloudvox.com">CloudVox </a>made an API that does exactly that &#8211; you give it a phone number, and it tells you the carrier and if its a cell-phone or landline. Its 100% free, with no API keys/credentials required. </p>
<p>Its hosted at <a href="http://digits.cloudvox.com">digits.cloudvox.com</a>, along with example calls/responses (<a href="http://help.cloudvox.com/kb/digits/digits-phone-number-location-lookup-api">full docs are here</a>). It speaks JSON over HTTP.</p>
<p>This gives us a much better user experience:</p>
<p>1) User inputs their number, no carrier dropdown needed</p>
<p>2) We use CloudVox&#8217;s API to determine their carrier</p>
<p>3) Try to send them an SMS, and have them confirm ownership in the normal way (i.e., enter a confirmation code)</p>
<p>This will cover most people, and is free outside of the development time. If there was an error (i.e., we couldn&#8217;t find the number with CloudVox&#8217;s API, or we did but the carrier doesn&#8217;t support mail-to-SMS), we can fall back to Twilio or Tropo. We&#8217;re still paying a few cents here and there, but the default case is free.</p>
<p>Here&#8217;s some example code in PHP, for querying CloudVox&#8217;s API:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code44'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47044"><td class="code" id="p470code44"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">/* Finds the carrier for the given phone number using CloudVox's API. Returns the carrier name as a string on success, or false if the carrier couldn't be determined */</span>
	<span style="color: #000000; font-weight: bold;">function</span> findCarrier<span style="color: #009900;">&#40;</span><span style="color: #000088;">$phoneNumber</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$carrier</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will contain the carriers name as a string if we are able to look it up</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// attempt to lookup the number with the CloudVox API</span>
		<span style="color: #000088;">$requestUrl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://digits.cloudvox.com/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$phoneNumber</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.json'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$apiResponse</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$requestUrl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Note: needs code to handle the error case of file_get_contents</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$apiResponse</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$responseJson</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/json_decode"><span style="color: #990000;">json_decode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$apiResponse</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$responseJson</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allocation</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$responseJson</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allocation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">carrier_name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$carrier</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$responseJson</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">allocation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">carrier_name</span><span style="color: #339933;">;</span>			
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$carrier</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will be false or the name of the carrier</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phoneNumber'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// user has submitted a form via GET, containing a field called phoneNumber</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// collect the phoneNumber and remove any non-numeric chars</span>
		<span style="color: #000088;">$phoneNumber</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#[^0-9]#'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><a href="http://www.php.net/strip_tags"><span style="color: #990000;">strip_tags</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phoneNumber'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$carrier</span> <span style="color: #339933;">=</span> findCarrier<span style="color: #009900;">&#40;</span><span style="color: #000088;">$phoneNumber</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$carrier</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/stripos"><span style="color: #990000;">stripos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$carrier</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'verizon'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				sendWithVerizon<span style="color: #009900;">&#40;</span><span style="color: #000088;">$phoneNumber</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/stripos"><span style="color: #990000;">stripos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$carrier</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'at&amp;t'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				sendWithATT<span style="color: #009900;">&#40;</span><span style="color: #000088;">$phoneNumber</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// other carrier. you'd really want to fall back to Twilio/Tropo here, and/or log the carrier so you can add it later</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Unknown Carrier: <span style="color: #006699; font-weight: bold;">{$carrier}</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// send SMS via Twilio or Tropo instead</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// show the form</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;form&gt;'</span> <span style="color: #339933;">.</span> 
			 <span style="color: #0000ff;">'&lt;label for=&quot;phoneNumber&quot;&gt;Phone Number&lt;/label&gt;'</span> <span style="color: #339933;">.</span>
			 <span style="color: #0000ff;">'&lt;input type=&quot;text&quot; name=&quot;phoneNumber&quot; /&gt;'</span> <span style="color: #339933;">.</span>
			 <span style="color: #0000ff;">'&lt;/form&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/finding-the-carrier-of-a-cell-phone-number-in-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Facebook Graph API requires Access Token for Feed Access</title>
		<link>http://illuminatikarate.com/blog/facebook-graph-api-requires-access-token-for-feed-access/</link>
		<comments>http://illuminatikarate.com/blog/facebook-graph-api-requires-access-token-for-feed-access/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 18:49:58 +0000</pubDate>
		<dc:creator>Richard Gabriel</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/?p=442</guid>
		<description><![CDATA[On June 3rd, Facebook updated the Graph API to require an access token to pull wall post data from public Facebook pages. This change can cause scripts to stop working, so here is a quick solution to pull wall post data from public Facebook pages with an access token. [...]]]></description>
			<content:encoded><![CDATA[<p>On June 3rd, Facebook <a href="http://developers.facebook.com/blog/post/510/">updated the Graph API</a> to require an access token to pull wall post data from public Facebook pages.  This change can cause scripts to stop working, so here is a quick solution to pull wall post data from public Facebook pages with an access token.<span id="more-442"></span></p>
<p>Consider the following code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p442code48'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44248"><td class="code" id="p442code48"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_init"><span style="color: #990000;">curl_init</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$retData</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_exec"><span style="color: #990000;">curl_exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <a href="http://www.php.net/curl_close"><span style="color: #990000;">curl_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$retData</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p442code49'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44249"><td class="code" id="p442code49"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$profile_id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1234567890&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'feed_data'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://graph.facebook.com/<span style="color: #006699; font-weight: bold;">{$profile_id}</span>/feed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Before the recent changes, this was all you needed to load a Facebook page&#8217;s feed.  You could load a public page&#8217;s feed by simply pulling from graph.facebook.com/{profile_id}/feed.  With the recent changes you just have to make a small modification and you&#8217;re good to go.</p>
<p>Here is the updated code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p442code50'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44250"><td class="code" id="p442code50"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$profile_id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;1234567890&quot;</span><span style="color: #339933;">;</span>		
&nbsp;
<span style="color: #666666; font-style: italic;">//App Info, needed for Auth</span>
<span style="color: #000088;">$app_id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;0001234567890&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$app_secret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;abc123ebf123f3g5g6j&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//retrieve auth token</span>
<span style="color: #000088;">$authToken</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;https://graph.facebook.com/oauth/access_token?type=client_cred&amp;client_id=<span style="color: #006699; font-weight: bold;">{$app_id}</span>&amp;client_secret=<span style="color: #006699; font-weight: bold;">{$app_secret}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'feed_data'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> fetchUrl<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;https://graph.facebook.com/<span style="color: #006699; font-weight: bold;">{$profile_id}</span>/feed?<span style="color: #006699; font-weight: bold;">{$authToken}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Be sure to use https instead of http, needed for OAuth.  You&#8217;ll also need to <a href="http://developers.facebook.com">create a simple Facebook app</a> to get an App ID and Secret key.  Once done, just swap out the variables in the above script for the proper values and you&#8217;re off to the races!</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/facebook-graph-api-requires-access-token-for-feed-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Submitting a Contact Form via AJAX From Your Facebook Page</title>
		<link>http://illuminatikarate.com/blog/submitting-a-contact-form-via-ajax-from-your-facebook-page/</link>
		<comments>http://illuminatikarate.com/blog/submitting-a-contact-form-via-ajax-from-your-facebook-page/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 03:57:08 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[FBJS]]></category>
		<category><![CDATA[FBML]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/blog/?p=297</guid>
		<description><![CDATA[Note: this post over over 2 years old and may need modifications. We recently created a contact submission form on a client&#8217;s Facebook page, and were not satisfied with the default user experience. For starters, the form opened a new window, and there was no way to redirect the [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em>Note: this post over over 2 years old and may need modifications.</em></p>
<p>We recently created a contact submission form on a client&#8217;s Facebook page, and were not satisfied with the default user experience. For starters, the form opened a new window, and there was no way to redirect the user back to a confirmation message on the Facebook page. </p>
<p>We decided to submit the form via AJAX instead, and show the confirmation message directly on the Facebook page. This way the user would not have to leave the Facebook page, resulting in a smoother user experience. We couldn&#8217;t find a good explanation of how to do this on Google, so after figuring it out I decided to go ahead and write it up. </p>
<p>The following example will show you how to submit a basic contact form using AJAX from within your Facebook page. All HTML and Javascript that follows should be pasted directly into the &#8220;Edit FBML&#8221; screen on Facebook.</p>
<p><span id="more-297"></span>Here&#8217;s the example form HTML we&#8217;ll use for the rest of this article. It&#8217;s just two text fields (name and email) and a submit button:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p297code54'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p29754"><td class="code" id="p297code54"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;http://mywebsite.com/form_submit.php&quot; method=&quot;post&quot;&gt;
     &lt;p&gt;
          &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;
          &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; /&gt;
     &lt;/p&gt;
     &lt;p&gt;
          &lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;
          &lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; /&gt;
     &lt;/p&gt;
     &lt;button type=&quot;submit&quot; onclick=&quot;return submitAjaxForm();&quot;&gt;Submit&lt;/button&gt;
     &lt;p id=&quot;ajaxMessage&quot;&gt;&lt;/p&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>There&#8217;s three things you should take note of:</p>
<ol>
<li>The form&#8217;s <b>action</b> attribute is set to a page on mywebsite.com, not facebook.com (replace mywebsite.com with your own domain)</li>
<li>The submit button has an onSubmit event that calls a function submitAjaxForm, which we&#8217;ll define shortly</li>
<li>At the end of the form is an empty paragraph tag. We&#8217;ll use this space to display messages to the user.</li>
</ol>
<p>On our server, form_submit.php is a simple PHP script that logs the submissions, and sends back a message for the user letting them know the submission was successful. It might look something like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p297code55'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p29755"><td class="code" id="p297code55"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
     log_submission<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Thank you for your submission!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Of course, your script will be more sophisticated than this one, and doesn&#8217;t have to be written in PHP. Its on your server, so you can handle logging the submission however you like. Just make sure the output is valid <a href="http://wiki.developers.facebook.com/index.php/FBML">FBML</a>.</p>
<p>With the form HTML added to your Facebook page and the logging script in place, the only thing left is adding the Javascript to submit the form via AJAX and show the confirmation message.</p>
<p class="note"><b>Note:</b> Facebook does not allow you to use any Javascript function you like, for security purposes. Instead they&#8217;ve created a library of Javascript functions for accessing the DOM, AJAX, and event binding called <a href="http://wiki.developers.facebook.com/index.php/FBJS">FBJS</a>. These functions are used in the example below.</p>
<p>We&#8217;ll now define the submitAjaxForm() function we referenced earlier in our submit button&#8217;s onSubmit event:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p297code56'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p29756"><td class="code" id="p297code56"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;&lt;!--</span>
<span style="color: #003366; font-weight: bold;">function</span> submitAjaxForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
	<span style="color: #006600; font-style: italic;">// declare a new FBJS AJAX object</span>
	<span style="color: #003366; font-weight: bold;">var</span> ajax <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ajax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	ajax.<span style="color: #660066;">responseType</span> <span style="color: #339933;">=</span> Ajax.<span style="color: #660066;">FBML</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// define a callback to handle the response from the server</span>
	ajax.<span style="color: #660066;">ondone</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ajaxMessage'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setInnerFBML</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// let the user know we're sending the data	</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ajaxMessage'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setInnerXHTML</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Submitting your information, please wait...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// collect field values</span>
	<span style="color: #003366; font-weight: bold;">var</span> queryParams <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'name'</span> <span style="color: #339933;">:</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'email'</span> <span style="color: #339933;">:</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	ajax.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://mywebsite.com/form_submit.php'</span><span style="color: #339933;">,</span> queryParams<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">//--&gt;&lt;/script&gt;</span></pre></td></tr></table></div>

<p><em>Note: The opening and closing HTML comments embedded in the Javascript are important, so leave them intact.</em></p>
<p>The example is fairly self explanatory, but here&#8217;s what&#8217;s happening:</p>
<ol>
<li>Declare a new Ajax object, which is one of the FBJS classes. We then set its response type to FBML (Ajax.RAW and Ajax.JSON are also accepted).</li>
<li>Define a callback function to handle the response from the server. In this case, our function simply takes the response from the server and displays it in the #ajaxMessage paragraph we defined earlier.</li>
<li>Update the user to let them know their data is being submitted using FBJS&#8217;s setInnerFBML function.</li>
<li>Collect the form field&#8217;s values into an array named queryParams, using FBJS&#8217;s getElementById and getValue functions. Although getElementById is similar to the standard Javascript function, it accounts for the random slugs Facebook injects into div id&#8217;s for security (View Source on a Facebook page and look at the div ID&#8217;s to see this in action).</li>
<li>Send the AJAX request, using FBJS&#8217; Ajax.post function. The second argument is optional, and should be an array containing the query parameters.</li>
<li>&#8220;return false;&#8221; prevents the form&#8217;s normal submit behavior</li>
</ol>
<p>That&#8217;s all there is to it! If you have any questions or if I should clarify a section, let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/submitting-a-contact-form-via-ajax-from-your-facebook-page/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>

