<?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>dBaines.com</title>
	<atom:link href="http://dbaines.com/feed/?post_type=tutorials" rel="self" type="application/rss+xml" />
	<link>http://dbaines.com</link>
	<description>Portfolio and Blog of David Baines, South Australian Web Developer</description>
	<lastBuildDate>Tue, 24 Apr 2012 11:21:17 +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>DotNetNuke Quick Tip: Remove gap between input and button</title>
		<link>http://dbaines.com/blog/archive/dotnetnuke-quick-tip-remove-gap-between-input-and-button/</link>
		<comments>http://dbaines.com/blog/archive/dotnetnuke-quick-tip-remove-gap-between-input-and-button/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 02:24:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=1988</guid>
		<description><![CDATA[A quick little tutorial on how to remove a gap between the DNN search skin object.]]></description>
			<content:encoded><![CDATA[<p>If you're working on a DNN skin that requires the search button to be next to the search input you're going to be annoyed by a tiny little gap that likes to insert itself between your elements.</p>
<p>Fear not, though, it's a relatively simple issue to fix!</p>
<p>The file you need to edit is: <code class="inline-code">/admin/Skins/search.ascx</code>.</p>
<p>Inside that file on line 6 you'll find a sneaky little non-breaking space element. Delete that element.</p>
<figure id="attachment_1991" aria-describedby="figcaption_attachment_1991" style="width: 868px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2012/02/gv_nbsp.jpg"><img class="size-full wp-image-1991" title="non-breaking space" src="http://dbaines.com/blog/wp-content/uploads/2012/02/gv_nbsp.jpg" alt="" width="858" height="335" /></a><figcaption id="figcaption_attachment_1991"> non-breaking space</figcaption></figure>
<p>&nbsp;</p>
<p>Save that file and upload it if necessary and you'll notice your search bar goes from:</p>
<figure id="attachment_1989" aria-describedby="figcaption_attachment_1989" style="width: 247px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2012/02/gv_boo.jpg"><img class="size-full wp-image-1989" title="Boo!" src="http://dbaines.com/blog/wp-content/uploads/2012/02/gv_boo.jpg" alt="" width="237" height="67" /></a><figcaption id="figcaption_attachment_1989">Boo!</figcaption></figure>
<p>to:</p>
<figure id="attachment_1992" aria-describedby="figcaption_attachment_1992" style="width: 247px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2012/02/gv_yay.jpg"><img class="size-full wp-image-1992" title="Yay!" src="http://dbaines.com/blog/wp-content/uploads/2012/02/gv_yay.jpg" alt="" width="237" height="67" /></a><figcaption id="figcaption_attachment_1992">Yay!</figcaption></figure>
<span class="message important">It's important to note that this skin file is a core file and there's always the possibility that the file will be replaced or completely changed during an upgrade. </span>]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/dotnetnuke-quick-tip-remove-gap-between-input-and-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Custom Post Type Art Gallery Tutorial</title>
		<link>http://dbaines.com/blog/archive/wordpress-custom-post-type-art-gallery-tutorial/</link>
		<comments>http://dbaines.com/blog/archive/wordpress-custom-post-type-art-gallery-tutorial/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 05:06:36 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=1920</guid>
		<description><![CDATA[This lengthy tutorial will teach you how to set up a custom post type for an art gallery and implementing the colorbox popups instead of full-post pages, then implementing a custom homepage with a slider of your latest images.]]></description>
			<content:encoded><![CDATA[<p>This is a multi-page post of tutorials that will teach you how to create a custom post type for an art gallery, template it and then implement a custom home page with a slider.</p>
<p>I'll be working with the as-of-writing default template, TwentyEleven, but the steps can really be applied to any skin as long as you acknowledge the dimensions of your website before you start.</p>
<p>This introductory page will act as a guide to break up the tutorial in to easy to digest chunks, so here's a run down of each page and what you will learn:</p>
<h2 class="subheader"><a title="Wordpress Custom Post Type Art Gallery Tutorial - Part 2" href="?page=2">Page Two</a></h2>
<figure id="attachment_1471" aria-describedby="figcaption_attachment_1471" style="width: 601px" class="wp-caption aligncenter"><a href="/blog/wp-content/uploads/2012/01/customposttype.jpg"><img class="size-full wp-image-1471" title="Custom Post Type Settings" src="/blog/wp-content/uploads/2012/01/customposttype.jpg" alt="" width="591" height="398" /></a><figcaption id="figcaption_attachment_1471">Custom Post Type Settings</figcaption></figure>
<ul>
<li>Create an "artwork" custom post type using the Custom Post Type UI plugin</li>
<li>Apply additional image sizes using the Additional Image Sizes plugin</li>
<li>Creating  your first art gallery post</li>
</ul>
<h2 class="subheader"><a title="Wordpress Custom Post Type Art Gallery Tutorial - Part 3" href="?page=3">Page Three</a></h2>
<figure id="attachment_1492" aria-describedby="figcaption_attachment_1492" style="width: 650px" class="wp-caption aligncenter"><a href="/blog/wp-content/uploads/2012/01/stylesadded.jpg"><img class="size-large wp-image-1492" title="Styling Added" src="/blog/wp-content/uploads/2012/01/stylesadded-1024x444.jpg" alt="" width="640" height="277" /></a><figcaption id="figcaption_attachment_1492">Styling Added</figcaption></figure>
<ul>
<li>Creating a template to display your artwork post type as a gallery rather than a series of posts.</li>
</ul>
<h2 class="subheader"><a title="Wordpress Custom Post Type Art Gallery Tutorial - Part 4" href="?page=4">Page Four</a></h2>
<figure id="attachment_1507" aria-describedby="figcaption_attachment_1507" style="width: 310px" class="wp-caption aligncenter"><a href="/blog/wp-content/uploads/2012/01/Colorboxed.jpg"><img class="size-medium wp-image-1507" title="Colorboxed" src="/blog/wp-content/uploads/2012/01/Colorboxed-300x243.jpg" alt="" width="300" height="243" /></a><figcaption id="figcaption_attachment_1507">Colorboxed</figcaption></figure>
<ul>
<li>Implementing Colorbox to display your "full posts" as a popup gallery</li>
</ul>
<h2 class="subheader"><a title="Wordpress Custom Post Type Art Gallery Tutorial - Part 5" href="?page=5">Page Five</a></h2>
<figure id="attachment_1523" aria-describedby="figcaption_attachment_1523" style="width: 650px" class="wp-caption aligncenter"><a href="/blog/wp-content/uploads/2012/01/slidercustomised.jpg"><img class="size-large wp-image-1523" title="Customised the Slider" src="/blog/wp-content/uploads/2012/01/slidercustomised-1024x579.jpg" alt="" width="640" height="361" /></a><figcaption id="figcaption_attachment_1523">Customised the Slider</figcaption></figure>
<ul>
<li>Creating a homepage for your website</li>
<li>Using Sudo Slider to develop a "latest artwork" slider.</li>
</ul>
<h2 class="subheader"><a title="Wordpress Custom Post Type Art Gallery Tutorial - Part 6" href="?page=6">Page Six</a></h2>
<figure id="attachment_1531" aria-describedby="figcaption_attachment_1531" style="width: 650px" class="wp-caption aligncenter"><a href="/blog/wp-content/uploads/2012/01/postmetastyled.jpg"><img class="size-large wp-image-1531" title="Styled titles and dates" src="/blog/wp-content/uploads/2012/01/postmetastyled-1024x475.jpg" alt="" width="640" height="296" /></a><figcaption id="figcaption_attachment_1531">Styled titles and dates</figcaption></figure>
<ul>
<li>Adding titles and dates to your slider and styling</li>
<li>Linking the titles directly to a colorbox popup</li>
</ul>
<h2 class="subheader"><a title="Wordpress Custom Post Type Art Gallery Tutorial - Epilogue" href="?page=7">Epilogue</a></h2>
<ul>
<li>Download final template from Github</li>
<li>Other tutorials to keep going with</li>
</ul>
<p>Ready to get started? Head on over to Part Two.</p>]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/wordpress-custom-post-type-art-gallery-tutorial/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Adding Google +1 Buttons to Colorbox</title>
		<link>http://dbaines.com/blog/archive/adding-google-1-buttons-to-colorbox/</link>
		<comments>http://dbaines.com/blog/archive/adding-google-1-buttons-to-colorbox/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 21:02:21 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[colorbox]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plus one]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=1704</guid>
		<description><![CDATA[A quick run-down with code examples on how to add the google +1 button to your colorbox popups. These can be great if you have a portfolio set up like mine, where each colorbox popup is actually a post.]]></description>
			<content:encoded><![CDATA[<p>Something I've recently enabled in my theme (<a title="dBaines 2011 WordPress Template available at GitHub" href="http://dbaines.com/blog/archive/dbaines2011-wordpress-theme-now-on-github/">available on GitHub</a>!) is Google +1 buttons.</p>
<p>Here I'll detail the steps I took to add the +1 buttons to my artwork and motion portfolio pages.</p>
<p>First you need to understand the logic behind my portfolio. The artwork page is actually a list of WordPress posts that have the <em>post-type</em> of artwork, so each picture has it's own post and it's own permalink. This is essential for the +1 buttons, as they each need to have their own <acronym title="Uniform Resource Locator">URL</acronym> to +1 independent of each other.</p>
<p>If you are using a different <acronym title="Content Management System">CMS</acronym>, just ensure that each image (or whatever you're <a title="Colorbox" href="http://colorpowered.com/colorbox/" target="_blank">colorboxing</a>™) has a unique <acronym title="Uniform Resource Locator">URL</acronym>, even if it's just the <acronym title="Uniform Resource Locator">URL</acronym> of the image itself.</p>
<h2 class="subheader">Step 1: Adding the <acronym title="Uniform Resource Locator">URL</acronym> somewhere that Javascript can access</h2>
<p>In my wordpress loop I needed to add the permalink for the WordPress post, in this case I just used the "data-*" attribute:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">&lt;a href=&quot;/path/to/image.jpg&quot; data-permalink=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;galleryThumbnail&quot; title=&quot;my really cool image&quot;&gt;</pre></div></figure>
<p>If you're just going to use the <acronym title="Uniform Resource Locator">URL</acronym> of the image you can skip this step, as we can just steal the <acronym title="Uniform Resource Locator">URL</acronym> from the "href" attribute.</p>
<h2 class="subheader">Step 2: The Javascript</h2>
<p>I already had a custom "title" set up in my colorbox call, as I wanted the option for the user to download the image. Here is the script I had originally:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a.galleryThumbnail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>colorbox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
opacity<span style="color: #339933;">:</span> <span style="color:#800080;">0.92</span><span style="color: #339933;">,</span>
scalePhotos<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
maxHeight<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;90%&quot;</span><span style="color: #339933;">,</span>
maxWidth<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;90%&quot;</span><span style="color: #339933;">,</span>
title<span style="color: #339933;">:</span> <span style="color: #000000; 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: #000000; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> download <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;span id=&quot;cboxDownload&quot;&gt;&lt;a href=&quot;'</span><span style="color: #339933;">+</span>url<span style="color: #339933;">+</span><span style="color: #0000ff;">'&quot; title=&quot;Download This Image&quot;&gt;&lt;strong&gt;Download&lt;/strong&gt;&lt;/a&gt;&lt;/span&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;span id=&quot;cboxTitleLeft&quot;&gt;'</span><span style="color: #339933;">+</span>title<span style="color: #339933;">+</span><span style="color: #0000ff;">'&lt;/span&gt;'</span><span style="color: #339933;">+</span>download<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>I already have some variables set up in there that's pulling information from the markup. This gives you an idea on how we're going to access the permalink, so let's start the magic!</p>
<h2 class="subheader">The Magic</h2>
<p>We can't just add in the typical &lt;g:plus&gt; tag in the script since it just plain doesn't work. Conveniently, <a title="Google's PlusOne button docs" href="http://code.google.com/apis/+1button/#jsapi" target="_blank">the plus guys have a handy-dandy documentation page</a> that covers just about everything we need to tackle this problem. We need to use the Javascript <acronym title="Application Programming Interface">API</acronym> instead, which is really quite easy.</p>
<p>We need to set up a target element which is as simple as adding an empty element to the return, like so:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;span id=&quot;cboxTitleLeft&quot;&gt;'</span><span style="color: #339933;">+</span>title<span style="color: #339933;">+</span><span style="color: #0000ff;">'&lt;/span&gt;&lt;span id=&quot;cboxGplus&quot;&gt;&lt;/span&gt;'</span><span style="color: #339933;">+</span>download<span style="color: #339933;">;</span></pre></div></figure>
<p>So I've added an empty span with the ID of cboxGplus. Now we want to target that element with the <code class="inline-code">gapi.plusone.render</code> command. At the end of the title function, add a comma after the last curly brace ("}") then add in the colorbox "onComplete" option:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">&nbsp;
title<span style="color: #339933;">:</span> <span style="color: #000000; 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: #000000; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> download <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;span id=&quot;cboxDownload&quot;&gt;&lt;a href=&quot;'</span><span style="color: #339933;">+</span>url<span style="color: #339933;">+</span><span style="color: #0000ff;">'&quot; title=&quot;Download This Image&quot;&gt;&lt;strong&gt;Download&lt;/strong&gt;&lt;/a&gt;&lt;/span&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;span id=&quot;cboxTitleLeft&quot;&gt;'</span><span style="color: #339933;">+</span>title<span style="color: #339933;">+</span><span style="color: #0000ff;">'&lt;/span&gt;&lt;span id=&quot;cboxGplus&quot;&gt;&lt;/span&gt;'</span><span style="color: #339933;">+</span>download<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
onComplete<span style="color: #339933;">:</span> <span style="color: #000000; 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: #666666; font-style: italic;">// This is where the plusone magic will happen</span>
<span style="color: #009900;">&#125;</span>
&nbsp;</pre></div></figure>
<p>The onComplete function, funilly enough, will run when the colorbox pop up finishes loading. So once the image has loaded and everything's settled, we'll tell Google to render that button for us. Do it Google! Do it!</p>
<p>Inside the function add the following two lines:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> permalink <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;data-permalink&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
gapi<span style="color: #339933;">.</span>plusone<span style="color: #339933;">.</span>render<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cboxGplus&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;size&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;small&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #339933;">:</span> permalink<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>The variable is pulling the permalink from the data-permalink attribute. If you're using the full-size image as the <acronym title="Uniform Resource Locator">URL</acronym> to +1 then change the "data-permalink" to "href".</p>
<p>The render command is being triggered for the "cboxGplus" element. It's being rendered as a "small" button, showing the count and the href is being pulled from the permalink variable. Neat-o.</p>
<h2 class="subheader">All together</h2>
<p>So now our complete code looks like this:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">&nbsp;
title<span style="color: #339933;">:</span> <span style="color: #000000; 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: #000000; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> download <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;span id=&quot;cboxDownload&quot;&gt;&lt;a href=&quot;'</span><span style="color: #339933;">+</span>url<span style="color: #339933;">+</span><span style="color: #0000ff;">'&quot; title=&quot;Download This Image&quot;&gt;&lt;strong&gt;Download&lt;/strong&gt;&lt;/a&gt;&lt;/span&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;span id=&quot;cboxTitleLeft&quot;&gt;'</span><span style="color: #339933;">+</span>title<span style="color: #339933;">+</span><span style="color: #0000ff;">'&lt;/span&gt;&lt;span id=&quot;cboxGplus&quot;&gt;&lt;/span&gt;'</span><span style="color: #339933;">+</span>download<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
onComplete<span style="color: #339933;">:</span> <span style="color: #000000; 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: #666666; font-style: italic;">// +1 Button</span>
<span style="color: #000000; font-weight: bold;">var</span> permalink <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;data-permalink&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
gapi<span style="color: #339933;">.</span>plusone<span style="color: #339933;">.</span>render<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cboxGplus&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;size&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;small&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #339933;">:</span> permalink<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;</pre></div></figure>
<p>And after some <acronym title="Cascading Style Sheets">CSS</acronym> tweaking, check it out, it's now showing up:<br />
<em>Note: This example has "count" set to false, so the count bubble is hidden.</em></p>
<figure id="attachment_1716" aria-describedby="figcaption_attachment_1716" style="width: 310px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2011/07/plusone-working.jpg"><img class="size-medium wp-image-1716" title="The +1 Button On Colorbox" src="http://dbaines.com/blog/wp-content/uploads/2011/07/plusone-working-300x241.jpg" alt="" width="300" height="241" /></a><figcaption id="figcaption_attachment_1716">The +1 Button On Colorbox</figcaption></figure>
<h2 class="subheader">See it in action</h2>
<p>This is now live on my website, over in either my <a href="/artwork">artwork</a> or <a href="/motion">motion</a> pages. <a title="dBaines 2011 WordPress Template available at GitHub" href="http://dbaines.com/blog/archive/dbaines2011-wordpress-theme-now-on-github/">The source is freely available over at GitHub</a>. The pages you're interested in are:</p>
<ul>
<li>/js/dbaines.js - Do a search for "// Colorboxing Artwork"</li>
<li>/loop.php - Do a search for "/* Artwork */" and look for the <strong>a</strong> tag.</li>
</ul>
<p>Hope that helps, let me know if you have any questions in the comments section below, or <a title="Drop me a line, or a square. Or if you really want to impress me, a trapezoid. Everyone likes those. " href="/about/#contact">drop me a line</a> via email.</p>]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/adding-google-1-buttons-to-colorbox/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding Zenphoto Option to WordPress Custom Post Type Search</title>
		<link>http://dbaines.com/blog/archive/adding-zenphoto-option-to-wordpress-custom-post-type-search/</link>
		<comments>http://dbaines.com/blog/archive/adding-zenphoto-option-to-wordpress-custom-post-type-search/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 04:45:14 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[zenphoto]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=1587</guid>
		<description><![CDATA[Following on from my Custom Post Types Search tutorial, we'll add a Zenphoto option that will switch the action and method of the form and the input name if a user clicks on it. ]]></description>
			<content:encoded><![CDATA[<p>This is an add-on tutorial to my previous tutorial, "<a href="http://dbaines.com/blog/archive/wordpress-custom-post-type-multiple-search/">WordPress Custom Post Type Search</a>".</p>
<p>This will walk you through how to add a Zenphoto option, and if the Zenphoto option is clicked, it will show further options to select title, description, tag or filename.</p>
<div class="ddlbox"><a href="/demos/wp_customsearch_zp/" title="View Demo" class="ddlbox_demo">View Demo</a></div>
<h2 class="subheader">Adding the Zenphoto option</h2>
<p>This part is pretty simple. Find your <code class="inline-code">#searchOptions</code> container we set up previously and add in this line:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;radio&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post_type&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;searchOptionsZenphoto&quot;</span> <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;searchOptionsZenphoto&quot;</span><span style="color: #339933;">&gt;</span>Search Zenphoto Only<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span></pre></div></figure>
<figure id="attachment_1599" aria-describedby="figcaption_attachment_1599" style="width: 356px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2011/03/zenphotooption.jpg"><img class="size-full wp-image-1599" title="The Zenphoto Option" src="http://dbaines.com/blog/wp-content/uploads/2011/03/zenphotooption.jpg" alt="" width="346" height="126" /></a><figcaption id="figcaption_attachment_1599">The Zenphoto Option</figcaption></figure>
<p>Now we have a new option to specifically search Zenphoto only.<br />
Notice I've also removed "Search All" since there's no way to consolidate the results from WordPress and Zenphoto without hacking the search results page to pull down both results. That's a little of scope for today's tutorial.</p>
<h2 class="subheader">jQuery</h2>
<p>Unlike the previous tutorial, the Zenphoto search won't go through WordPress at all, so we'll need to redirect the search to Zenphoto if that option is clicked.</p>
<p>Here's the heavily commented code I put together to do just that:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> thisOption <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Switching Form Types Depending On Which Option Is Selected</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchOptions input[name=post_type]&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</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: #006600; font-style: italic;">// Throw the ID in to a variable for easy access</span>
thisOption <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// If ZenPhoto is selected...</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>thisOption <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;searchOptionsZenphoto&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Set Zenphoto Form Settings</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#search&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
<span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;path/to/zenphoto/page/search/&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;post&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set Zenphoto Input Name</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchMain input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;words&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// If not ZenPhoto (WordPress)</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Set WordPress Form Settings</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;form#search&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
<span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;path/to/wordpress/&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;get&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set WordPress Input Name</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchMain input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;s&quot;</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;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>So now if we click on "Search Zenphoto Only" it will change the form to search action and method attributes to make it search your Zenphoto install. If we select any of the other options it will switch back to the WordPress settings. It will also modify the input field name since WordPress looks for "s" and Zenphoto looks for "words".</p>
<p>You will need to ensure you change the "action" values to your actual zenphoto and wordpress installs. The Zenphoto action will need "/page/search/" at the end to point to the Zenphoto search page.</p>
<h2 class="subheader">More Zenphoto Options</h2>
<p>By default Zenphoto includes search options of it's own:</p>
<figure id="attachment_1602" aria-describedby="figcaption_attachment_1602" style="width: 345px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2011/03/zenphotoadv_default.jpg"><img class="size-full wp-image-1602" title="Advanced Options" src="http://dbaines.com/blog/wp-content/uploads/2011/03/zenphotoadv_default.jpg" alt="" width="335" height="164" /></a><figcaption id="figcaption_attachment_1602">Advanced Options</figcaption></figure>
<p>So let's try and incorporate that in to our search box.</p>
<p>First add a new section to your search form:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>section id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;searchZPOptions&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_desc&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_desc&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> checked<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checked&quot;</span>  value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;desc&quot;</span>  <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_desc&quot;</span><span style="color: #339933;">&gt;</span>Search Description<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_filename&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_filename&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> checked<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checked&quot;</span>  value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;filename&quot;</span>  <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_filename&quot;</span><span style="color: #339933;">&gt;</span>Search Folder<span style="color: #339933;">/</span>Filename<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_tags&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_tags&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> checked<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checked&quot;</span>  value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tags&quot;</span>  <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_tags&quot;</span><span style="color: #339933;">&gt;</span>Search Tags<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_title&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_title&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> checked<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checked&quot;</span>  value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;title&quot;</span>  <span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SEARCH_title&quot;</span><span style="color: #339933;">&gt;</span>Search Title<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>section<span style="color: #339933;">&gt;</span></pre></div></figure>
<p>This code is mostly taken straight from the Zenphoto search form. By default they are all checked, but you can turn them off by removing the <code class="inline-code">checked="checked"</code> attribute.</p>
<p>We'll also add the following to our <acronym title="Cascading Style Sheets">CSS</acronym> to indent it a little to make it look like it's supposed to be apart of the ZenPhoto selection above it, and to hide it by default:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#searchZPOptions</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></figure>
<p>Then add the show/hide functions to your jQuery to show the additional options if a user clicks on the Zenphoto Option:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> thisOption <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Switching Form Types Depending On Which Option Is Selected</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchOptions input[name=post_type]&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</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: #006600; font-style: italic;">// Throw the ID in to a variable for easy access</span>
thisOption <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// If ZenPhoto is selected...</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>thisOption <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;searchOptionsZenphoto&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Show ZPOptions</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchZPOptions&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set Zenphoto Form Settings</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#search&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
<span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;path/to/zenphoto/page/search/&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;post&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set Zenphoto Input Name</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchMain input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;words&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// If not ZenPhoto (WordPress)</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Hide ZPOptions</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchZPOptions&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set WordPress Form Settings</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;form#search&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
<span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;path/to/wordpress/&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;get&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set WordPress Input Name</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchMain input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;s&quot;</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;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>So now if a user clicks on the Zenphoto option, it not only redirects the form, but also shows the Zenphoto tickboxes.</p>
<figure id="attachment_1601" aria-describedby="figcaption_attachment_1601" style="width: 357px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2011/03/zenphotoadv.jpg"><img class="size-full wp-image-1601" title="Advanced Search Options" src="http://dbaines.com/blog/wp-content/uploads/2011/03/zenphotoadv.jpg" alt="" width="347" height="206" /></a><figcaption id="figcaption_attachment_1601">Advanced Search Options</figcaption></figure>
<h2 class="subheader">Cleaning Up After Zenphoto</h2>
<p>Since WordPress uses <code class="inline-code">get</code> to retrieve the search terms, it's also going to send all of Zenphoto's SEARCH_* inputs to the WordPress search page. We can create a function that checks for a WordPress search and then removes those input fields:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Check for Submit press and delete ZenPhoto options from sending if on WordPress</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#searchsubmit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>click<span style="color: #009900;">&#40;</span><span style="color: #000000; 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: #b1b100;">if</span><span style="color: #009900;">&#40;</span>thisOption <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;searchOptionsZenphoto&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#SEARCH_desc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>remove<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#SEARCH_filename&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>remove<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#SEARCH_tags&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>remove<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#SEARCH_title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>remove<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;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>So now if somebody clicks the submit button, the script will check to see if thisOption has the Zenphoto value. If it doesn't, it's obviously a WordPress search, so we'll go ahead and remove those elements from being sent.</p>
<p>So your whole jQuery script should look something like this:<br />
<figure class="codeboxFig"><div class="codebox"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Show/Hide</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchAnchor&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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;#searchOptions&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</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: #003366; font-weight: bold;">var</span> thisOption <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Switching Form Types Depending On Which Option Is Selected</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchOptions input[name=post_type]&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</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: #006600; font-style: italic;">// Throw the ID in to a variable for easy access</span>
thisOption <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// If ZenPhoto is selected...</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>thisOption <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;searchOptionsZenphoto&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Show ZPOptions</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchZPOptions&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set Zenphoto Form Settings</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#search&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
<span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;path/to/zenphoto/page/search/&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;post&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set Zenphoto Input Name</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchMain input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;words&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// If not ZenPhoto (WordPress)</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// Hide ZPOptions</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchZPOptions&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set WordPress Form Settings</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;form#search&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
<span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;path/to/wordpress/&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;method&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;get&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Set WordPress Input Name</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchMain input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;s&quot;</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;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Check for Submit press and delete ZenPhoto options from sending if on WordPress</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>thisOption <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;searchOptionsZenphoto&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#SEARCH_desc&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#SEARCH_filename&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#SEARCH_tags&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#SEARCH_title&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</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;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure></p>
<p>Check out this demo to see it in action, using my old Zenphoto install I still had lying around on my server:<br />
<div class="ddlbox"><a href="/demos/wp_customsearch_zp/" title="View Demo" class="ddlbox_demo">View Demo</a></div></p>]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/adding-zenphoto-option-to-wordpress-custom-post-type-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Custom Post Type Search</title>
		<link>http://dbaines.com/blog/archive/wordpress-custom-post-type-multiple-search/</link>
		<comments>http://dbaines.com/blog/archive/wordpress-custom-post-type-multiple-search/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 12:26:14 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=1551</guid>
		<description><![CDATA[Learn how to add some options to your Wordpress search bar to allow the user to specify exactly where they want to search.]]></description>
			<content:encoded><![CDATA[<figure id="attachment_1552" aria-describedby="figcaption_attachment_1552" style="width: 310px" class="wp-caption alignright"><a href="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-searchoptions.jpg"><img class="size-medium wp-image-1552" title="Search Options" src="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-searchoptions-300x167.jpg" alt="" width="300" height="167" /></a><figcaption id="figcaption_attachment_1552">Drop-down search options, dBaines.com 2011</figcaption></figure>
<p>I like having an easy-to-use search bar that isn't redundant and doesn't require several different search bars to do things that a single search bar should be able to do. PhpBB, I'm looking at you.</p>
<p>Today I'll teach you how to add some options to your WordPress search bar to search for several different things. The search bar will allow the user to search:</p>
<ul>
<li> All post types and categories</li>
<li>Only blog post types</li>
<li>Only portfolio post types (which in this example will be an array of three different kinds of post types in itself)</li>
<li>Only in the tutorial category</li>
</ul>
<p>Set up your search bar as you normally would in your template. For this example, I'm just going to have a search bar on an empty page, for simplicity's sake.</p>
<h2 class="subheader">Modifying your template</h2>
<p>Open up the template that has your search bar in it. Your search form should look something like this:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">&nbsp;
&lt;form id=&quot;search&quot; name=&quot;searchform&quot; method=&quot;get&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&lt;section id=&quot;searchMain&quot;&gt;
&lt;input type=&quot;search&quot; id=&quot;s&quot; name=&quot;s&quot; title=&quot;Search Blog&quot; placeholder=&quot;Search My Website&quot; /&gt;
&lt;button type=&quot;submit&quot; value=&quot;search&quot; id=&quot;searchsubmit&quot;&gt;Search&lt;/button&gt;
&lt;/section&gt;
&lt;/form&gt;
&nbsp;</pre></div></figure>
<figure id="attachment_1558" aria-describedby="figcaption_attachment_1558" style="width: 240px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-customsearch-01.jpg"><img class="size-full wp-image-1558" title="Figure 1" src="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-customsearch-01.jpg" alt="" width="230" height="38" /></a><figcaption id="figcaption_attachment_1558">Fig. 1 - Your Form So Far</figcaption></figure>
<p>Here I've used a HTML5 element called <code class="inline-code">section</code> to wrap around my form elements. You can use a <code class="inline-code">div</code> if you're not comfortable using HTML5 elements. We need a container element for these elements because the options are going to be in a separate container, but still in side the form.<br />
Create another <code class="inline-code">section</code> element underneath the searchMain section, and call it something like searchOptions. Populate this element with some radio buttons and some labels, as you would if you were setting up any old regular form with a radio selection. The "name" for these radio buttons will be "post_type". Set up the values to represent what you would like the post_type to be when the user searches. My code at this point is now looking like this:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">&nbsp;
&lt;form id=&quot;search&quot; name=&quot;searchform&quot; method=&quot;get&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&lt;section id=&quot;searchMain&quot;&gt;
&lt;input type=&quot;search&quot; id=&quot;s&quot; name=&quot;s&quot; title=&quot;Search Blog&quot; placeholder=&quot;Search My Website&quot; /&gt;
&lt;button type=&quot;submit&quot; value=&quot;search&quot; id=&quot;searchsubmit&quot;&gt;Search&lt;/button&gt;
&lt;/section&gt;
&lt;section id=&quot;searchOptions&quot;&gt;
&lt;input type=&quot;radio&quot; value=&quot;all&quot; name=&quot;post_type&quot; id=&quot;searchOptionsAll&quot; checked /&gt; &lt;label for=&quot;searchOptionsAll&quot;&gt;Search All&lt;/label&gt;&lt;br /&gt;
&lt;input type=&quot;radio&quot; value=&quot;post&quot; name=&quot;post_type&quot; id=&quot;searchOptionsBlog&quot; /&gt; &lt;label for=&quot;searchOptionsBlog&quot;&gt;Search Blog Only&lt;/label&gt;&lt;br /&gt;
&lt;input type=&quot;radio&quot; value=&quot;portfolio&quot; name=&quot;post_type&quot; id=&quot;searchOptionsPortfolio&quot; /&gt; &lt;label for=&quot;searchOptionsPortfolio&quot;&gt;Search Portfolio Only&lt;/label&gt;&lt;br /&gt;
&lt;input type=&quot;radio&quot; value=&quot;tutorials&quot; name=&quot;post_type&quot; id=&quot;searchOptionsTutorials&quot; /&gt; &lt;label for=&quot;searchOptionsTutorials&quot;&gt;Search Tutorials Only&lt;/label&gt;
&lt;/section&gt;
&lt;/form&gt;
&nbsp;</pre></div></figure>
<figure id="attachment_1559" aria-describedby="figcaption_attachment_1559" style="width: 243px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-customsearch-02.jpg"><img class="size-full wp-image-1559" title="Figure 2" src="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-customsearch-02.jpg" alt="" width="233" height="133" /></a><figcaption id="figcaption_attachment_1559">Fig 2 - The Search Options!</figcaption></figure>
<p>Note: I've added the "<code class="inline-code">checked</code>" attribute to the first radio button. This will act as the default action. This way you don't need to worry about coding in a fallback in case someone doesn't select an option.<br />
If you would like a different option to be used as the default search, remove the <code class="inline-code">checked</code> attribute from the first radio button and add it to the one you want to be the default.<br />
So now we've got a pretty good looking form coming together.</p>
<h2 class="subheader">Functions.php</h2>
<p>You've got a pretty swanky form going now, but does it actually do anything? If you click search, you'll notice it sends <code class="inline-code">?s=%searchterm%&amp;post_type=%yourselection%</code> to the search results page up in the <acronym title="Uniform Resource Locator">URL</acronym>. We're now going to take advantage of those GET variables and do some pretty cool things with them.</p>
<p>Open up your <code class="inline-code">functions.php</code> and at the bottom, paste in the following code:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">/***********************************
*
* SEARCH FILTER
* http://speckyboy.com/2010/09/19/10-useful-wordpress-search-code-snippets/
*
***********************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> SearchFilter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</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;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_search</span> or <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_feed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Portfolio</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;portfolio&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_type'</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;">'artwork'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'websites'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'motion'</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: #666666; font-style: italic;">// Tutorials</span>
<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;tutorials&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category_name'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'tutorials'</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;">// EVERYTHING! MWAHAHAHAHAHA</span>
<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;all&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_type'</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;">'artwork'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'websites'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'motion'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</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: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// This filter will jump into the loop and arrange our results before they're returned</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pre_get_posts'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'SearchFilter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>I like to always attribute links to the places I find the snippets of code I use, so you'll notice I've included a link to <a title="10 Useful WordPress Search Snippets" href="http://speckyboy.com/2010/09/19/10-useful-wordpress-search-code-snippets/" target="_blank">the site where I originally found the snippet we'll be using today</a>.<br />
I've added two checks, the first one checks if the page we're on is a search, the second one checks if we're looking a feed. The feed part is optional and you can remove it. I included it because I also wanted to have these queries available as custom feeds.</p>
<p>Once the feed or search check is confirmed, it will move on to look at the $_GET values for the "post_type" variable:</p>
<ul>
<li>If it finds "portfolio" it will create a custom query to return all posts in the "artwork", "websites" and "motion" post types that match the search terms. These are proper custom post types I had previously set up in the back-end using the Custom Post Type UI plugin.</li>
<li>If it finds "tutorials" it will create a custom query to return all posts in the tutorials category that match the search terms.</li>
<li>if it finds "all" it will create a custom query similar to the first one, however instead of just returning those three post types, it also returns "post" post types, which are the default blog post types for WordPress. This way you're essentially searching all four post types for the same term.</li>
</ul>
<p>Notice I didn't need to set up a custom query for the "Search blog only" option. If you look back at the code for the radio buttons, the value it sends is simply "post". As we've learned in the code snippet above, "post" is the post type for the default WordPress blog posts. The variable the search form sends to the search results page is post_type, which is actually a real variable you can pass to WordPress at any time. As such when you search only the blog it will send ?post_type=post to the search results page and WordPress will know exactly what to do with this out of the box.</p>
<p>Now you'll probably want to change the post_types above to use the post_types you want to search for on your own WordPress install. Unless you find yourself in the incredibly coincidental scenario of having exactly the same sort of post types as me. In which case, high five!</p>
<p>So now your search form should be fully functional and ready to go!</p>
<h2 class="subheader">Some jQuery magic</h2>
<p>If you're like me, you like a search bar to not take up too much room, and be fairly easy to access. These new options seem to take up a lot of space and don't look very good. What can we do about that? Well, how about we add a show/hide options button? Sounds pretty good to me!</p>
<p>Go back to your search form template and add in a link just after the search button. Make sure to give it a unique ID so we can target it in jQuery later. Here I've called mine searchAnchor:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">  <span style="color: #339933;">&lt;</span>section id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;searchMain&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;search&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;s&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;s&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Search Blog&quot;</span> placeholder<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Search My Website&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>button type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;search&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;searchsubmit&quot;</span><span style="color: #339933;">&gt;</span>Search<span style="color: #339933;">&lt;/</span>button<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;searchAnchor&quot;</span><span style="color: #339933;">&gt;</span>Search Options<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>section<span style="color: #339933;">&gt;</span></pre></div></figure>
<figure id="attachment_1560" aria-describedby="figcaption_attachment_1560" style="width: 351px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-customsearch-03.jpg"><img class="size-full wp-image-1560" title="Figure 3" src="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-customsearch-03.jpg" alt="" width="341" height="116" /></a><figcaption id="figcaption_attachment_1560">Figure 3 - Complete Form with New Link</figcaption></figure>
<p>Okay, great. Now we have a little link there. If you already have a scripts file with other jQuery business in it, open that up. If not, create a <code class="inline-code">scripts.js</code> file and dump it in to your theme folder. Enter in the following code:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="javascript" style="font-family:monospace;">$<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;#searchAnchor&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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;#searchOptions&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</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: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>Make sure you link up your new scripts.js file to your theme, then try it out! Now when you click the link it hides the options. Clicking it again shows them again! Woo! But we'll probably want it hidden by default. So open up your <acronym title="Cascading Style Sheets">CSS</acronym> file and add the following:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="css" style="font-family:monospace;">&nbsp;
<span style="color: #cc00cc;">#searchOptions</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;</pre></div></figure>
<p>Lookin' good, good lookin'. Now it's hidden by default, and clicking on the "search options" link shows them. Now all that's left is to style that puppy up. Add some background colours, borders and all sorts of crazy CSS3 goodness and you'll soon end up with a pretty swanky lookin' form.</p>
<figure id="attachment_1552" aria-describedby="figcaption_attachment_1552" style="width: 310px" class="wp-caption aligncenter"><a href="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-searchoptions.jpg"><img class="size-medium wp-image-1552" title="Search Options" src="http://dbaines.com/blog/wp-content/uploads/2011/03/wp-searchoptions-300x167.jpg" alt="" width="300" height="167" /></a><figcaption id="figcaption_attachment_1552">Drop-down search options, dBaines.com 2011</figcaption></figure>
<p>If I'm still using the db2011 theme while you're reading this then there should be a <strong>live, working demo</strong> right there in the top right corner of this very website!</p>]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/wordpress-custom-post-type-multiple-search/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Keyboard Navigation for EasySlider and SudoSlider</title>
		<link>http://dbaines.com/blog/archive/keyboard-navigation-for-easyslider/</link>
		<comments>http://dbaines.com/blog/archive/keyboard-navigation-for-easyslider/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 09:59:21 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=1131</guid>
		<description><![CDATA[<p><a href="#sudoSlider">Looking for instructions for SudoSlider?</a></p>
<p><a title="EasySlider 1.7 by Alen Grakalic" href="http://cssglobe.com/post/5780/easy-slider-17-numeric-navigation-jquery-slider" target="_blank">EasySlider </a>is pretty awesome. You just chuck it in, tell it what container to slide with and you're all good to go. It's definitely my go-to slider when working on new projects. When implementing it on a recent project there was only one thing missing: Keyboard navigation. I'm a huge fan of keyboard navigation, probably just because I'm really lazy and I'm always impressed when I can move things about using my arrow keys. Luckily for me, keyboard navigation is super simple to add, and Alen kindly provides the non-minified code so we can hack away and customise to our liking!</p>
<p><span id="more-1131"></span></p>
<p>Firstly, open up the non-minified version and find the  function:</p>

<p>Directly under that, simply <br />&#160;<br /> <a href="http://dbaines.com/blog/archive/keyboard-navigation-for-easyslider/" class="read_more">Continue Reading</a></p>]]></description>
			<content:encoded><![CDATA[<span class="message info">This tutorial was written for EasySlider 1.7, if you are using a different version this may not apply.</span>
<p><a href="#sudoSlider">Looking for instructions for SudoSlider?</a></p>
<p><a title="EasySlider 1.7 by Alen Grakalic" href="http://cssglobe.com/post/5780/easy-slider-17-numeric-navigation-jquery-slider" target="_blank">EasySlider </a>is pretty awesome. You just chuck it in, tell it what container to slide with and you're all good to go. It's definitely my go-to slider when working on new projects. When implementing it on a recent project there was only one thing missing: Keyboard navigation. I'm a huge fan of keyboard navigation, probably just because I'm really lazy and I'm always impressed when I can move things about using my arrow keys. Luckily for me, keyboard navigation is super simple to add, and Alen kindly provides the non-minified code so we can hack away and customise to our liking!</p>
<p><span id="more-1131"></span></p>
<p>Firstly, open up the non-minified version and find the <code class="inline-code">this.each</code> function:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">this<span style="color: #339933;">.</span><a href="http://www.php.net/each"><span style="color: #990000;">each</span></a><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></figure>
<p>Directly under that, simply paste in the following code chunk:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Keypress Listeners</span>
<span style="color: #000000; font-weight: bold;">function</span> checkKey<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">.</span>keyCode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">37</span><span style="color: #339933;">:</span>
e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
animate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;prev&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: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">:</span>
e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
animate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;next&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: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Keypress Listener Support</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #339933;">.</span>browser<span style="color: #339933;">.</span>mozilla<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>keypress<span style="color: #009900;">&#40;</span>checkKey<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: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>keydown<span style="color: #009900;">&#40;</span>checkKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></figure>
<p>You're all set! The CheckKey function keeps an eye out for any keystrokes. If it finds key "37" (left arrow) it triggers the previous slide animation to start. If it finds key "39" (right arrow) it triggers the next slide.</p>
<p>But David, you say. What If I only want keyboard navigation on some pages and not others? Well you, I say, simply make it an <em>option</em>. Now if you've never looked at a jQuery plugin before this might be a little scary, but we can simply add an option that we can pass a true/false setting to when we call our script. Look for this code:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">$<span style="color: #339933;">.</span>fn<span style="color: #339933;">.</span>easySlider <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// default configuration properties</span>
<span style="color: #000000; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
prevId<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'prevBtn'</span><span style="color: #339933;">,</span>
prevText<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'Previous'</span><span style="color: #339933;">,</span>
nextId<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'nextBtn'</span><span style="color: #339933;">,</span>	</pre></div></figure>
<p>Go to the end of the list of options, it should be <code class="inline-code">numericId: false</code>. You'll probably notice that every option has a comma at the end, except for the last one. Add a comma to the end of this line and create a new line. On the new line, add the following: <code class="inline-code">keyboard: false</code></p>
<p>Your options code should now look something like this:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// default configuration properties</span>
<span style="color: #000000; font-weight: bold;">var</span> defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
prevId<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'prevBtn'</span><span style="color: #339933;">,</span>
prevText<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'Previous'</span><span style="color: #339933;">,</span>
nextId<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'nextBtn'</span><span style="color: #339933;">,</span>
nextText<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'Next'</span><span style="color: #339933;">,</span>
controlsShow<span style="color: #339933;">:</span>	<span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
controlsBefore<span style="color: #339933;">:</span>	<span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
controlsAfter<span style="color: #339933;">:</span>	<span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
controlsFade<span style="color: #339933;">:</span>	<span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
firstId<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'firstBtn'</span><span style="color: #339933;">,</span>
firstText<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'First'</span><span style="color: #339933;">,</span>
firstShow<span style="color: #339933;">:</span>		<span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
lastId<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'lastBtn'</span><span style="color: #339933;">,</span>
lastText<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'Last'</span><span style="color: #339933;">,</span>
lastShow<span style="color: #339933;">:</span>		<span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
vertical<span style="color: #339933;">:</span>		<span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
speed<span style="color: #339933;">:</span> 			<span style="color: #cc66cc;">800</span><span style="color: #339933;">,</span>
auto<span style="color: #339933;">:</span>			<span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
pause<span style="color: #339933;">:</span>			<span style="color: #cc66cc;">2000</span><span style="color: #339933;">,</span>
continuous<span style="color: #339933;">:</span>		<span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
numeric<span style="color: #339933;">:</span> 		<span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
numericId<span style="color: #339933;">:</span> 		<span style="color: #0000ff;">'controls'</span><span style="color: #339933;">,</span>
keyboard<span style="color: #339933;">:</span>		<span style="color: #009900; font-weight: bold;">false</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> </pre></div></figure>
<p>Now go back to the code you added earlier. Before the checkKey function, add: <code class="inline-code">if(options.keyboard) {</code>, then at the bottom of the new code (below both the checkKey function and the keyboard listener support section, add a curly bracket: <code class="inline-code">}</code>.</p>
<p>Your checkKey code should look like this:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>options<span style="color: #339933;">.</span>keyboard<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Keypress Listeners</span>
<span style="color: #000000; font-weight: bold;">function</span> checkKey<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">.</span>keyCode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">37</span><span style="color: #339933;">:</span>
e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
animate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;prev&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: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">:</span>
e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
animate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;next&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: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Keypress Listener Support</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #339933;">.</span>browser<span style="color: #339933;">.</span>mozilla<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>keypress<span style="color: #009900;">&#40;</span>checkKey<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: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>keydown<span style="color: #009900;">&#40;</span>checkKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></figure>
<p>That's it! You've added your option! What this does is it checks if the option "keyboard" is true and if it is it runs the code in the brackets. Remember how we set the option to default to false? Well, we'll now need to call the slider with the option set to true:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.homepageSliderWrapper&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>easySlider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
continuous<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
prevId<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;largePrev&quot;</span><span style="color: #339933;">,</span>
nextId<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;largeNext&quot;</span><span style="color: #339933;">,</span>
keyboard<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>Now go to the page your slider is on and press your left/right arrows and watch that baby slide!</p>
<p>Alternatively, you can set the keyboard option to default to true, and on the pages you don't want it to be on, call it as false.</p>
<h2 class="subheader" id="sudoSlider">SudoSlider</h2>
<p><a href="http://webbies.dk/SudoSlider" target="_blank">SudoSlider</a> is based on EasySlider and as such it's a pretty easy to adapt these instructions to SudoSlider. All you need to do is change the "animate" calls to "goToSlide".</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Keypress Listeners</span>
<span style="color: #000000; font-weight: bold;">function</span> checkKey<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">.</span>keyCode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">37</span><span style="color: #339933;">:</span>
e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
animate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;prev&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: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">:</span>
e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
animate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;next&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: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></figure>
<p>To:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Keypress Listeners</span>
<span style="color: #000000; font-weight: bold;">function</span> checkKey<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">.</span>keyCode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">37</span><span style="color: #339933;">:</span>
e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
goToSlide<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'prev'</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: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">:</span>
e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
goToSlide<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'next'</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: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></figure>]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/keyboard-navigation-for-easyslider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[DotNetNuke] Add a logout button to the HouseMenu Admin Menu</title>
		<link>http://dbaines.com/blog/archive/dnn-housemenu-add-a-logout-button/</link>
		<comments>http://dbaines.com/blog/archive/dnn-housemenu-add-a-logout-button/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 05:09:56 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=1118</guid>
		<description><![CDATA[<p>The one thing I hate about the HouseMenu SkinObject for DNN is that there's no native logout method without typing in /Logoff.aspx. Here's a quick little jQuery snippet that will add a logout button to your admin menu.<br />&#160;<br /> <a href="http://dbaines.com/blog/archive/dnn-housemenu-add-a-logout-button/" class="read_more">Continue Reading</a></p>]]></description>
			<content:encoded><![CDATA[<p>The one thing I hate about the HouseMenu SkinObject for DNN is that there's no native logout method without typing in /Logoff.aspx. Here's a quick little jQuery snippet that will add a logout button to your admin menu.</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a[title='Portal Administration']&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><a href="http://www.php.net/next"><span style="color: #990000;">next</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>append<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;li id=&quot;HouseMenuNavLogOut&quot;&gt;&lt;a href=&quot;/Logoff.aspx&quot;&gt;Log Out&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/dnn-housemenu-add-a-logout-button/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ZenCart: Adding Category and Description to Featured Products Centerbox</title>
		<link>http://dbaines.com/blog/archive/zencart-adding-category-and-description-to-featured-products-centerbox/</link>
		<comments>http://dbaines.com/blog/archive/zencart-adding-category-and-description-to-featured-products-centerbox/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 12:52:10 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=1482</guid>
		<description><![CDATA[I'll show you how to edit your featured_products.php file to add the description and category name of the products in your featured products box. ]]></description>
			<content:encoded><![CDATA[<span class="message info">This information is for ZenCart 1.3.9x only. It is untested on older versions.</span>
<p>So ZenCart has a massive back-end that even the most experienced Zenners can get lost in. Even with all the menus and obscene amount of options, there aren't any settings to configure for the centerboxes.</p>
<p>The only way to customise these boxes is to edit the code. Luckily, the ZenCart guys have put all the product lookup functions in <code class="inline-code">/includes/functions/functions_lookup.php</code>, and have lookups for both the category and the description. We can drop those functions in to the centerbox code quite easily, even though their FAQs and knowledgebase don't really mention it much.</p>
<p>Read on if you're interested in seeing a breakdown of how it's done, or you can <a href="#wholelot">jump right to the solution</a>.</p>
<h2 class="subheader">1. Backing up and Overriding</h2>
<p>The first step is to create some overrides for the files we need to edit, rather than editing the core file.</p>
<p>Fire up your <acronym title="File Transfer Protocol">FTP</acronym> client and go to <code class="inline-code">/includes/modules/</code>. Download the centerbox you would like to edit. In this example I'll do the featured products box. So download <code class="inline-code">featured_products.php</code>. If there isn't already, create a folder with the same name as your template.</p>
<p>Upload the file you just created in to this folder, and start editing.</p>
<h2 class="subheader">2. Adding the Category Name</h2>
<p>If you're using a template that's based on the default "contemporary green" template, the line you need to find should be 73, and should start with <code class="inline-code">'text' =&gt; (($featured_products</code>.</p>
<p>In this line, find where the product name is displayed. The bit of code we're looking for is:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;' .  zen_href_link(zen_get_info_page(<span style="color: #006699; font-weight: bold;">$featured_products-&gt;fields</span>['products_id']),  'cPath=' .  <span style="color: #006699; font-weight: bold;">$productsInCategory</span>[<span style="color: #006699; font-weight: bold;">$featured_products-&gt;fields</span>['products_id']] .  '&amp;products_id=' . <span style="color: #006699; font-weight: bold;">$featured_products-&gt;fields</span>['products_id']) .  '&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #0000ff;">' . $featured_products-&gt;fields['</span>products_name<span style="color: #0000ff;">'] . '</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></div></figure>
<span class="message info"><em>Aside</em>: To make things a little more consistent with the rest of ZenCart, I added a h1.itemTitle around the link, and also got rid of all the heinous &lt;br&gt;s.</span>
<p>Directly after the link (or <code class="inline-code">h1</code> in my case) ends, add the following code: <code class="inline-code">&lt;h2&gt;' . zen_get_category_name($featured_products-&gt;fields['master_categories_id'], $_SESSION['languages_id']) . '&lt;/h2&gt;</code></p>
<p>The function <code class="inline-code">zen_get_category_name</code> takes two values. The first is the category id, which featured_products already creates for you as <code class="inline-code">$featured_products-&gt;fields['master_categories_id']</code> and the second value is the language. You can get the users language by using <code class="inline-code">$_SESSION['languages_id']</code>. This function will result in printing out the category name.</p>
<p>If you've put a h1 around your product title your line should now look like this:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'text'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_image'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span> and PRODUCTS_IMAGE_NO_IMAGE_STATUS <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">''</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> zen_href_link<span style="color: #009900;">&#40;</span>zen_get_info_page<span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cPath='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$productsInCategory</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;products_id='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> zen_image<span style="color: #009900;">&#40;</span>DIR_WS_IMAGES <span style="color: #339933;">.</span> <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH<span style="color: #339933;">,</span> IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;h1 class=&quot;itemTitle&quot;&gt;&lt;a href=&quot;'</span> <span style="color: #339933;">.</span> zen_href_link<span style="color: #009900;">&#40;</span>zen_get_info_page<span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cPath='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$productsInCategory</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;products_id='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;/h1&gt;&lt;h2&gt;'</span> <span style="color: #339933;">.</span>  zen_get_category_name<span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'master_categories_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>  <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'languages_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$products_price</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>Save the file and you should now see the category listed right under the title for your featured products.</p>
<h2 class="subheader">3. Adding the Description</h2>
<p>Directly after the <code class="inline-code">h2</code> ends, add the following code:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div<span style="color: #339933;">&gt;</span><span style="color: #0000ff;">' .  zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($featured_products-&gt;fields['</span>products_id<span style="color: #0000ff;">'], $_SESSION['</span>languages_id<span style="color: #0000ff;">']))), PRODUCT_LIST_DESCRIPTION) . '</span><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></figure>
<p>There are a few nested functions here. <code class="inline-code">zen_trunc_string</code> asks ZenCart how many characters the description should be before it truncates it. The default is 150. This can be changed in the your admin settings. The <code class="inline-code">zen_clean_html</code> and <code class="inline-code">stripslashes</code> are functions that remove any <acronym title="HyperText Markup Language">HTML</acronym> so you don't end up messing up your layout with cut off code.<br />
<code class="inline-code">zen_get_product_description</code> is the function that finds the description for the product. It takes the product id and the language. The products id is conveniently accessed via <code class="inline-code">$featured_products-&gt;fields['product_id']</code>.</p>
<h2 class="subheader" id="wholelot">4. The Whole Lot</h2>
<p>After all of that, your text line should end up like so. If you're just joining us, this should be around line 73 in <code class="inline-code">includes/modules/YOUR_TEMPLATE/featured_posts.php</code>.</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'text'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_image'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span>  <span style="color: #0000ff;">''</span> and PRODUCTS_IMAGE_NO_IMAGE_STATUS <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">''</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span> <span style="color: #339933;">.</span>  zen_href_link<span style="color: #009900;">&#40;</span>zen_get_info_page<span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">'cPath='</span> <span style="color: #339933;">.</span>  <span style="color: #000088;">$productsInCategory</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span>  <span style="color: #0000ff;">'&amp;products_id='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>  <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> zen_image<span style="color: #009900;">&#40;</span>DIR_WS_IMAGES <span style="color: #339933;">.</span>  <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_image'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>  <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>  IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH<span style="color: #339933;">,</span>  IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;h1  class=&quot;itemTitle&quot;&gt;&lt;a href=&quot;'</span> <span style="color: #339933;">.</span>  zen_href_link<span style="color: #009900;">&#40;</span>zen_get_info_page<span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">'cPath='</span> <span style="color: #339933;">.</span>  <span style="color: #000088;">$productsInCategory</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span>  <span style="color: #0000ff;">'&amp;products_id='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>  <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span>  <span style="color: #0000ff;">'&lt;/a&gt;&lt;/h1&gt;&lt;h2&gt;'</span> <span style="color: #339933;">.</span>   zen_get_category_name<span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'master_categories_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>   <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'languages_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/h2&gt;&lt;div&gt;'</span> <span style="color: #339933;">.</span>   zen_trunc_string<span style="color: #009900;">&#40;</span>zen_clean_html<span style="color: #009900;">&#40;</span><a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span>zen_get_products_description<span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured_products</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>  <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'languages_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> PRODUCT_LIST_DESCRIPTION<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$products_price</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<p>Save your file and refresh your page. Voila! Product title, product category, product description and price, all listed in the box.</p>
<p>With a little bit of styling, you end up with something like this:</p>
<p style="text-align: center;"><img class="size-full wp-image-1089   aligncenter" title="Featured Products with Description and Category" src="http://dbaines.com/blog/wp-content/uploads/2010/09/zcFeaturedProducts.jpg" alt="ZenCart Featured Products" width="681" height="491" /></p>
<p style="text-align: center;">]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/zencart-adding-category-and-description-to-featured-products-centerbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress: Conditional Post Type Function</title>
		<link>http://dbaines.com/blog/archive/wordpress-conditional-post-type-function/</link>
		<comments>http://dbaines.com/blog/archive/wordpress-conditional-post-type-function/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 11:34:04 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[db2010]]></category>
		<category><![CDATA[Post Types]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=1545</guid>
		<description><![CDATA[Use get_post_type inside your loop to create custom displays for different post types. ]]></description>
			<content:encoded><![CDATA[<p>Custom post types are pretty neat. By putting the following code (kindly taken from <a title="Custom Post Types on Homepage" href="http://www.wprecipes.com/how-to-display-custom-post-types-on-your-wordpress-blog-homepage" target="_blank">WPRecipes</a>) in your functions.php, you can include all post types in your blog page:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_get_posts<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$query</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> is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_search<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_archive<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;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post_type'</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;">'post'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tutorial'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'update'</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;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'pre_get_posts'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_get_posts'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></figure>
<figure id="attachment_636" aria-describedby="figcaption_attachment_636" style="width: 310px" class="wp-caption alignright"><a href="http://dbaines.com/blog/wp-content/uploads/2010/04/dbaines.com-2010-04-post-types.png"><img class="size-medium wp-image-636  " title="Three Post Types" src="http://dbaines.com/blog/wp-content/uploads/2010/04/dbaines.com-2010-04-post-types-300x233.png" alt="" width="300" height="233" /></a><figcaption id="figcaption_attachment_636">Three types: Microblog, Post &amp; Tutorial</figcaption></figure>
<p>That's great, but what if I want all of my post types to be shown on my blog page but look slightly different. Well, you can use <code class="inline-code">get_post_type</code> to do exactly that.</p>
<p><code class="inline-code">get_post_type</code> requires a post ID to be supplied, so you can use <code class="inline-code">&lt;?php get_post_type(get_the_ID()); ?&gt;</code> inside the loop to check against the current posts' post_type.</p>
<p>You can echo that code inside your post class to allow changes on a purely <acronym title="Cascading Style Sheets">CSS</acronym> level, by targeting the my_post_type class. However, if you want to go all crazy and have a completely different output for each post, you could do something like this inside your loop:</p>
<figure class="codeboxFig"><div class="codebox"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> get_post_type<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">$type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;tutorial&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
.. tutorial display ..
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;update&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
.. update display ..
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
.. normal post display ..
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></figure>
<p>And viola! You now have completely customisable post type displays, all in the single loop.</p>]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/wordpress-conditional-post-type-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zenpressed Mod &#8211; Thumbnails for Multimedia (mp3/flv)</title>
		<link>http://dbaines.com/blog/archive/zenpressed-mp3-flv-thumbnails/</link>
		<comments>http://dbaines.com/blog/archive/zenpressed-mp3-flv-thumbnails/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 03:17:08 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[multimedia]]></category>
		<category><![CDATA[zenphoto]]></category>

		<guid isPermaLink="false">http://dbaines.com/?p=453</guid>
		<description><![CDATA[This is a mod that will make Zenpressed show thumbnails for FLV and MP3 formats.]]></description>
			<content:encoded><![CDATA[<h2 class="subheader">Introduction</h2>
<figure id="attachment_473" aria-describedby="figcaption_attachment_473" style="width: 287px" class="wp-caption alignright"><img class="size-full wp-image-473" title="Zenpressed - Broken Link" src="http://dbaines.com/blog/wp-content/uploads/2009/08/zpressed-flv-before.jpg" alt="Before" width="277" height="128" /><figcaption id="figcaption_attachment_473">Before</figcaption></figure>
<p>I decided to expand my art gallery to include some FLVs and MP3s and found that my trusty Zenpressed plugin doesn't check if the file is an FLV or an MP3, and instead just tries to embed the mp3/flv as a thumbnail.</p>
<p>I looked around for a few different plugins that would recognise the multimedia formats, but none of them were as awesome as Zenpressed. Zenpressed hadn't been updated since the dawn of time so I didn't expect to find any help from their website.</p>
<p>Instead I dove in to the code and created a small hack for multimedia formats.</p>
<figure id="attachment_474" aria-describedby="figcaption_attachment_474" style="width: 287px" class="wp-caption alignright"><img class="size-full wp-image-474" title="Zenpressed - Fixed" src="http://dbaines.com/blog/wp-content/uploads/2009/08/zpressed-flv-after.jpg" alt="After" width="277" height="232" /><figcaption id="figcaption_attachment_474">After</figcaption></figure>
<p>It seemed fairly simple enough. At the moment, the plugin takes the image url and uses it as a thumbnail.<br />
For multimedia formats, Zenphoto requires an image to be made with the same filename as the multimedia file, uploaded to the same folder as the file.<br />
For example, the thumbnail for mymovie.flv would be mymovie.jpg, so all I really needed to do was put a script in that removed the file extension and add ".jpg" to the end of the url.</p>
<p>And guess what? It really was that simple.</p>
<h2 class="subheader">Installation</h2>
<ol>
<li>Navigate to your [wordpress install directory]/wp-includes/plugins folder.<br />
Download your zenpressed.php file, create another copy of it and back it up somewhere safe just to be careful.</li>
<li>Open up the zenpressed.php file in your favourite code editor.</li>
<li>Find line number 75<br />
The line below it should start with:<br />
<figure class="codeboxFig"><table class="codebox"><tr><td class="line_numbers"><pre>76
77
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Output</span>
<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span></pre></td></tr></table></figure><br />
This is where the file starts it's output, we want to modify the filename <acronym title="Uniform Resource Locator">URL</acronym> before then, so on line 75 enter the following code:<br />
<figure class="codeboxFig"><table class="codebox"><tr><td class="line_numbers"><pre>75
76
77
78
79
80
81
82
83
84
85
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Multimedia Replacement mod by dBaines.com - Replaces image.flv with image.jpg</span>
    <span style="color: #666666; font-style: italic;">// Get last three characters from filename</span>
    <span style="color: #000088;">$se</span> <span style="color: #339933;">=</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;">$s</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Check if FLV or MP3</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$se</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;flv&quot;</span> or <span style="color: #000088;">$se</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;mp3&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Remove last 3 characters from image filename, &quot;flv&quot;</span>
        <span style="color: #000088;">$s</span> <span style="color: #339933;">=</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;">$s</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Add &quot;jpg&quot; to filename</span>
        <span style="color: #000088;">$s</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;jpg&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// End Multimedia Replacement mod by dBaines.com</span></pre></td></tr></table></figure><br />
<strong> WARNING</strong>: If you have modified your zenpressed.php file in any way or have downloaded a fork or pre-modified version of it, then your line number will possibly not match. Please make sure you have the <a href="http://n00bism.net/dokuwiki/wordpress/zenpressed">official version</a> to make sure you are putting the code in the right place.</p>
<p>If you have a modified version of zenpressed you might not be sure what line to put this code on.<br />
It goes in the <strong>zenpressed_showphoto</strong> function, under the "generate data" section and before the "output" section.</li>
<li>Save and reupload the file and you're good to go!</li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://dbaines.com/blog/archive/zenpressed-mp3-flv-thumbnails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 4.732 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-18 06:33:42 -->
<!-- Compression = gzip -->
