<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Pro Blog Design</title>
	
	<link>http://www.problogdesign.com</link>
	<description>Advice for blog owners and designers on making a more attractive, usable and ultimately profitable blog.</description>
	<lastBuildDate>Mon, 30 Aug 2010 16:00:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ProBlogDesign" /><feedburner:info uri="problogdesign" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>ProBlogDesign</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FProBlogDesign" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FProBlogDesign" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FProBlogDesign" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/ProBlogDesign" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FProBlogDesign" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FProBlogDesign" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FProBlogDesign" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:browserFriendly>Thanks for looking here. It's free to subscribe to my feed and it means that each time I write a post, it will be sent straight to you. You'll be a WordPress and web design pro in no time! (Well, if you aren't already! ;) )</feedburner:browserFriendly><item>
		<title>Working With WordPress Shortcodes</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/0rPFivWmmBw/</link>
		<comments>http://www.problogdesign.com/wordpress/working-with-wordpress-shortcodes/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 16:00:46 +0000</pubDate>
		<dc:creator>Pippin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[shortcodes]]></category>
		<category><![CDATA[WordPress Hacks]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/?p=5776</guid>
		<description><![CDATA[<img src="http://www.problogdesign.com/wp-content/uploads/2010/08/PBDESIGN-shortcodes.png" alt="" title="PBDESIGN-shortcodes" width="560" height="145" class="alignnone size-full wp-image-5830" />

WordPress shortcodes are used frequently in plugins and themes as a way to achieve extra functionality, without the need to modify template files. You just <strong>type the shortcode word right into your post</strong>. Some plugins and themes use them to add event calendars, some for making <a href="http://codecanyon.net/item/premium-wordpress-announcements-plugin/113296">announcements</a>, while others use them for inserting <a href="http://wordpress.org/extend/plugins/contact-form-7/">contact forms</a>.

Simply, WP shortcodes are awesome.

However, what if you're a <strong>theme / plugin developer wishing to use them</strong> for your next great product, but you have no idea where to start? We're going to fix that in this tutorial.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/08/PBDESIGN-shortcodes.png"  alt=""  title="PBDESIGN-shortcodes"  width="560"  height="145"  class="alignnone size-full wp-image-5830" /></p>
<p>WordPress shortcodes are used frequently in plugins and themes as a way to achieve extra functionality, without the need to modify template files. You just <strong>type the shortcode word right into your post</strong>. Some plugins and themes use them to add event calendars, some for making <a href="http://codecanyon.net/item/premium-wordpress-announcements-plugin/113296" >announcements</a>, while others use them for inserting <a href="http://wordpress.org/extend/plugins/contact-form-7/" >contact forms</a>.</p>
<p>Simply, WP shortcodes are awesome.</p>
<p>However, what if you&#8217;re a <strong>theme / plugin developer wishing to use them</strong> for your next great product, but you have no idea where to start? We&#8217;re going to fix that in this tutorial.</p>
<h3>1 &#8211; Overview &#8211; Exactly Where We are Going</h3>
<p>We will start out by looking at the basic ways that we can use WP shortcodes, then we will move onto some more advanced tricks. After the usage sections, I&#8217;m going to show you some <strong>examples of real-world shortcodes</strong>, followed by even more ideas / references of what you could do with them.</p>
<h3>2 &#8211; Getting Into the Basics</h3>
<p>The first you thing you should always do when working with something WordPress, is check the <a href="http://codex.wordpress.org/Shortcode_API" >WordPress Codex</a>. It&#8217;s a great reference and starting point.</p>
<p>Shortcodes, like just about everything else in WordPress, can be created in the <strong>functions.php</strong> file, or from within your plugin file if you&#8217;re developing a plugin.</p>
<p>Let&#8217;s start simple by making a shortcode that we can use to add additional styles to some text.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> extra_style_shortcode<span style="color: #009900;" >&#40;</span> <span style="color: #000088;" >$atts</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >=</span> <span style="color: #009900; font-weight: bold;" >null</span> <span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
   <span style="color: #b1b100;" >return</span> <span style="color: #0000ff;" >'&lt;span style=&quot;color: blue; text-decoration: underline;&quot;&gt;'</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'&lt;/span&gt;'</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'extra-style'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'extra_style_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>This is a very simple example that serves almost no purpose, but easily illustrates the basics of shortcode creation. It allows us to do something like this in our WP posts/pages:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[extra-style]Hello World![/extra-style]</pre></div></div>

<p>and have it outputted like this:</p>
<p><span style="color: blue; text-decoration: underline;" >Hello World!</span></p>
<p>So what&#8217;s happening? It&#8217;s simple, we&#8217;re simply telling WordPress to put all of the text inside of the [ ] . . . [/ ] into a variable called <strong>$content</strong>, then outputting <strong> $content</strong> inside of a span tag that has some simple inline styling applied to it.</p>
<p>Okay, that was easy, now let&#8217;s get into something a little more complex. This time we&#8217;ll give the ability to define the color of the text using attributes.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> extra_style_shortcode<span style="color: #009900;" >&#40;</span> <span style="color: #000088;" >$atts</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >=</span> <span style="color: #009900; font-weight: bold;" >null</span> <span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
    <span style="color: #990000;" >extract</span><span style="color: #009900;" >&#40;</span>shortcode_atts<span style="color: #009900;" >&#40;</span><span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
		<span style="color: #0000ff;" >&quot;color&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'blue'</span><span style="color: #339933;" >,</span>
	<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$atts</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>   
   <span style="color: #b1b100;" >return</span> <span style="color: #0000ff;" >'&lt;span style=&quot;color: '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$color</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'; text-decoration: underline;&quot;&gt;'</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'&lt;/span&gt;'</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'extra-style'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'extra_style_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>Now we can do this:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[extra-style color=red]Hello World![/extra-style]</pre></div></div>

<p>and we&#8217;ll see: <span style="color: red; text-decoration: underline;" >Hello World!</span></p>
<p>or:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[extra-style color=orange]Hello World![/extra-style]</pre></div></div>

<p>and we&#8217;ll see: <span style="color: orange; text-decoration: underline;" >Hello World!</span>.</p>
<p>This example uses this bit of code</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" >    <span style="color: #990000;" >extract</span><span style="color: #009900;" >&#40;</span>shortcode_atts<span style="color: #009900;" >&#40;</span><span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
		<span style="color: #0000ff;" >&quot;color&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'blue'</span><span style="color: #339933;" >,</span>
	<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$atts</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<p>to extract the information inputted by the user for the variable <strong>color</strong>. We have also defined a default color of <span style="color: blue;" >blue</span> in case no color is defined.</p>
<p>Again, this example is pretty much useless, but its simplicity makes it very easy to understand.</p>
<p>Let&#8217;s get just a little bit more complex before moving on.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> extra_style_shortcode<span style="color: #009900;" >&#40;</span> <span style="color: #000088;" >$atts</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >=</span> <span style="color: #009900; font-weight: bold;" >null</span> <span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
    <span style="color: #990000;" >extract</span><span style="color: #009900;" >&#40;</span>shortcode_atts<span style="color: #009900;" >&#40;</span><span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
	<span style="color: #0000ff;" >&quot;color&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'blue'</span><span style="color: #339933;" >,</span>
        <span style="color: #0000ff;" >&quot;size&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'14px'</span><span style="color: #339933;" >,</span>
        <span style="color: #0000ff;" >&quot;padding&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'0px'</span><span style="color: #339933;" >,</span>
	<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$atts</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>   
   <span style="color: #b1b100;" >return</span> <span style="color: #0000ff;" >'&lt;span style=&quot;color: '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$color</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'; padding: '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$padding</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'; font-size: '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$size</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'; text-decoration: underline;&quot;&gt;'</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'&lt;/span&gt;'</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'extra-style'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'extra_style_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>By using a shortcode like this within a block of text:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[extra-style color=purple size=18px padding=5px]Hello World![/extra-style]</pre></div></div>

<p>we could see something like this:</p>
<blockquote><p>Elementum odio? Sed, <span style="padding: 5px; font-size: 18px; color: purple;" >Hello World!</span> proin pulvinar eros nascetur, massa urna aliquam turpis elit, adipiscing mauris montes ac, vel lacus placerat in adipiscing ridiculus rhoncus.</p></blockquote>
<p>Well that&#8217;s enough of the pointless examples; let&#8217;s look at some real shortcode examples.</p>
<h3>3 &#8211; Making an Information Box</h3>
<p>This shortcode example will let you include a nice little message box at the top of your post to help catch readers&#8217; eyes.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> box_shortcode<span style="color: #009900;" >&#40;</span> <span style="color: #000088;" >$atts</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >=</span> <span style="color: #009900; font-weight: bold;" >null</span> <span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
    <span style="color: #990000;" >extract</span><span style="color: #009900;" >&#40;</span> shortcode_atts<span style="color: #009900;" >&#40;</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
      <span style="color: #0000ff;" >'color'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'yellow'</span><span style="color: #339933;" >,</span>
      <span style="color: #0000ff;" >'size'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'medium'</span><span style="color: #339933;" >,</span>
      <span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$atts</span> <span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
      <span style="color: #b1b100;" >return</span> <span style="color: #0000ff;" >'
		&lt;style type=&quot;text/css&quot;&gt;
		.shortcode_box {
			padding: 2px 4px;
			border: 1px solid #ccc;
		}
		.yellow {
			background: #ffd149;
			color: #666;
		}
		.blue {
			background: #a0c5ef;
			color: #333;
		}
		.gray {
			background: #f0f0f0;
			color: #333;
		}
		&lt;/style&gt;
&nbsp;
      &lt;div class=&quot;shortcode_box '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$size</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >' '</span> <span style="color: #339933;" >.</span>  <span style="color: #000088;" >$color</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'&quot;&gt;'</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'&lt;/div&gt;'</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'box'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'box_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>Now we can use our &#8220;box&#8221; shortcode to produce something like this</p>
<div style="background: #ffd149; color: #666; border: 1px solid #ccc; padding: 2px 4px; margin-bottom: 15px;" >This is a message box with important information you should read.</div>
<p>by using this shortcode:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[box color=yellow]This is a message box with important information you should read.[/box]</pre></div></div>

<p>By changing the <strong>color</strong> variable, we can have different colors of boxes:</p>
<div style="background: #a0c5ef; color: #666; border: 1px solid #ccc; padding: 2px 4px; margin-bottom: 15px;" >This is a message box with important information you should read.</div>
<div style="background: #f0f0f0; color: #666; border: 1px solid #ccc; padding: 2px 4px; margin-bottom: 15px;" >This is a message box with important information you should read.</div>
<p>With a little more CSS, we could also control the size of the box, but I&#8217;ll leave that to you.</p>
<h3>4 &#8211; Create a Download Button</h3>
<p>The process for creating a download button is very similar to creating a message box: we simplu wrap the content of the button inside of a div with some special CSS3 styles applied to it.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> button_shortcode<span style="color: #009900;" >&#40;</span> <span style="color: #000088;" >$atts</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >=</span> <span style="color: #009900; font-weight: bold;" >null</span> <span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
    <span style="color: #990000;" >extract</span><span style="color: #009900;" >&#40;</span> shortcode_atts<span style="color: #009900;" >&#40;</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
      <span style="color: #0000ff;" >'color'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'blue'</span><span style="color: #339933;" >,</span>
      <span style="color: #0000ff;" >'size'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'medium'</span><span style="color: #339933;" >,</span>
      <span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$atts</span> <span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
      <span style="color: #b1b100;" >return</span> <span style="color: #0000ff;" >'
		&lt;style type=&quot;text/css&quot;&gt;
		.shortcode_button {
			padding: 2px 8px;
			border: 1px solid #ccc;
			border-radius: 10px;
			-webkit-border-radius: 10px;
			-moz-border-radius: 10px;
		}
		.black {
			background: #ffd149;
			background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#636363), to(#332F2F));
			background: -moz-linear-gradient(19% 75% 90deg,#332F2F, #636363);
			color: #f0f0f0;
			border-top-color: #1c1c1c;
			border-left-color: #1c1c1c;
			border-right-color: #525252;
			border-bottom-color: #525252;
		}
		.blue {
			background: #a0c5ef;
			background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#508BC7), to(#203F75));
			background: -moz-linear-gradient(19% 75% 90deg,#203F75, #508BC7);
			color: #f0f0f0;
			border-top-color: #023778;
			border-left-color: #023778;
			border-right-color: #26609e;
			border-bottom-color: #26609e;
		}
&nbsp;
		.large	{
			width: 200px;
		}
		.medium	{
			width: 120px;
		}
		.small	{
			width: 80px;
		}
		&lt;/style&gt;
&nbsp;
      &lt;div class=&quot;shortcode_button '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$size</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >' '</span> <span style="color: #339933;" >.</span>  <span style="color: #000088;" >$color</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'&quot;&gt;'</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'&lt;/div&gt;'</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'button'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'button_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>We can display our button by using:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[button color=black size=medium]<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >a</span> <span style="color: #000066;" >href</span><span style="color: #66cc66;" >=</span><span style="color: #ff0000;" >&quot;#&quot;</span>&gt;</span>Download<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >a</span>&gt;</span>[/button]</pre></div></div>

<p>which will give us:<br/>
<a href="http://www.problogdesign.com/wp-content/uploads/2010/08/black_button.png" ><img src="http://www.problogdesign.com/wp-content/uploads/2010/08/black_button.png"  alt=""  title="black_button"  width="153"  height="47"  class="alignnone size-full wp-image-5804" /></a></p>
<p>In order to control the size or color of the button, all we have to do is create a CSS class with the same name as the value we input for our <strong>size / color</strong> variables. For example, if we do <em>size=large</em> in our shortcode, we need a CSS class called <em>large</em> in our stylesheet. You can see I have included extra styles in my above example to illustrate some possible options.</p>
<h3>5 &#8211; Buttons and Boxes Together</h3>
<p>Shortcodes are great because they also let us combine them to a result like:</p>
<div style="background: #a0c5ef; color: #333; border: 1px solid #ccc; padding: 5px 8px; margin-bottom: 15px;;" >Porta ultricies. Amet odio amet, pellentesque elementum adipiscing sagittis enim, eu, proin placerat sed pid cum? Dictumst turpis integer. Adipiscing, porttitor scelerisque! Lorem turpis porttitor.</p>
<p>Integer in, odio mattis ac! Nascetur augue odio in risus, arcu nunc, phasellus ultrices lectus velit, et tincidunt tristique. Integer vel pulvinar purus magnis.</p>
<div style="background: #ffd149; background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#636363), to(#332F2F));background: -moz-linear-gradient(19% 75% 90deg,#332F2F, #636363);color: #f0f0f0;border-top-color: #1c1c1c;border-left-color: #1c1c1c;border-right-color: #525252;border-bottom-color: #525252; padding: 2px 8px;border: 1px solid #ccc;border-radius: 10px;-webkit-border-radius: 10px;-moz-border-radius: 10px; width: 80px;border-top-color: #1c1c1c;border-left-color: #1c1c1c;border-right-color: #525252;border-bottom-color: #525252;" ><a href="#" >Download</a></div>
</div>
<p>by using a shortcode like:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[box color=blue]Porta ultricies. Amet odio amet, pellentesque elementum adipiscing sagittis enim, eu, proin placerat sed pid cum? Dictumst turpis integer. Adipiscing, porttitor scelerisque! Lorem turpis porttitor.
&nbsp;
Integer in, odio mattis ac! Nascetur augue odio in risus, arcu nunc, phasellus ultrices lectus velit, et tincidunt tristique. Integer vel pulvinar purus magnis.
&nbsp;
[button color=black size=small]<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >a</span> <span style="color: #000066;" >href</span><span style="color: #66cc66;" >=</span><span style="color: #ff0000;" >&quot;#&quot;</span>&gt;</span>Download[/button][/box]</pre></div></div>

<p>There is one small hitch, though. By default, WordPress does not allow you to embed shortcodes within other shortcodes. In order to get around that, we have to add a line to our <strong>functions.php</strong> or main plugin file:</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" >add_filter<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'the_content'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'do_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<p>This will make WordPress process both sets of shortcodes.</p>
<h3>6 &#8211; Show Related Posts</h3>
<p>This is a really handy shortcode we can use to display a list of posts related to the current post by comparing tags.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> related_posts_shortcode<span style="color: #009900;" >&#40;</span> <span style="color: #000088;" >$atts</span> <span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	<span style="color: #990000;" >extract</span><span style="color: #009900;" >&#40;</span>shortcode_atts<span style="color: #009900;" >&#40;</span><span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
	    <span style="color: #0000ff;" >'limit'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'5'</span><span style="color: #339933;" >,</span>
	<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$atts</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;" >global</span> <span style="color: #000088;" >$wpdb</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$post</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$table_prefix</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
		<span style="color: #000088;" >$retval</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >'&lt;ul&gt;'</span><span style="color: #339933;" >;</span>
 		<span style="color: #666666; font-style: italic;" >// Get tags</span>
		<span style="color: #000088;" >$tags</span> <span style="color: #339933;" >=</span> wp_get_post_tags<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		<span style="color: #000088;" >$tagsarray</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >foreach</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$tags</span> <span style="color: #b1b100;" >as</span> <span style="color: #000088;" >$tag</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
			<span style="color: #000088;" >$tagsarray</span><span style="color: #009900;" >&#91;</span><span style="color: #009900;" >&#93;</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$tag</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >term_id</span><span style="color: #339933;" >;</span>
		<span style="color: #009900;" >&#125;</span>
		<span style="color: #000088;" >$tagslist</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >implode</span><span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >','</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$tagsarray</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;" >// Do the query</span>
		<span style="color: #000088;" >$q</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >&quot;SELECT p.*, count(tr.object_id) as count
			FROM <span style="color: #006699; font-weight: bold;" >$wpdb-&gt;term_taxonomy</span> AS tt, <span style="color: #006699; font-weight: bold;" >$wpdb-&gt;term_relationships</span> AS tr, <span style="color: #006699; font-weight: bold;" >$wpdb-&gt;posts</span> AS p WHERE tt.taxonomy ='post_tag' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id  = p.ID AND tt.term_id IN (<span style="color: #006699; font-weight: bold;" >$tagslist</span>) AND p.ID != <span style="color: #006699; font-weight: bold;" >$post-&gt;ID</span>
				AND p.post_status = 'publish'
				AND p.post_date_gmt &lt; NOW()
 			GROUP BY tr.object_id
			ORDER BY count DESC, p.post_date_gmt DESC
			LIMIT <span style="color: #006699; font-weight: bold;" >$limit</span>;&quot;</span><span style="color: #339933;" >;</span>
&nbsp;
		<span style="color: #000088;" >$related</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$wpdb</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >get_results</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$q</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;" >$related</span> <span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
			<span style="color: #b1b100;" >foreach</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$related</span> <span style="color: #b1b100;" >as</span> <span style="color: #000088;" >$r</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
				<span style="color: #000088;" >$retval</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >'
	&lt;li&gt;&lt;a title=&quot;'</span><span style="color: #339933;" >.</span>wptexturize<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$r</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >post_title</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&quot; href=&quot;'</span><span style="color: #339933;" >.</span>get_permalink<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$r</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&quot;&gt;'</span><span style="color: #339933;" >.</span>wptexturize<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$r</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >post_title</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&lt;/a&gt;&lt;/li&gt;
'</span><span style="color: #339933;" >;</span>
			<span style="color: #009900;" >&#125;</span>
		<span style="color: #009900;" >&#125;</span> <span style="color: #b1b100;" >else</span> <span style="color: #009900;" >&#123;</span>
			<span style="color: #000088;" >$retval</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >'
	&lt;li&gt;No related posts found&lt;/li&gt;
'</span><span style="color: #339933;" >;</span>
		<span style="color: #009900;" >&#125;</span>
		<span style="color: #000088;" >$retval</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >'&lt;/ul&gt;
'</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$retval</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
	<span style="color: #b1b100;" >return</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'related_posts'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'related_posts_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>We can show the related posts by using:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[related_posts]</pre></div></div>

<p><em>Credit goes to <a href="http://blue-anvil.com/archives/8-fun-useful-shortcode-functions-for-wordpress/" >Blue Anvil</a> for this shortcode.</em></p>
<h3>7 &#8211; Drop Caps With a Shortcode</h3>
<p><span style="display:block;float:left;font-size:50px;line-height:40px;margin:0 5px 0 0;" >D</span>rop caps are pretty and make your articles look really nice. They can really add some nice detail to post and make your site stand out above the rest.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> dropcap<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$atts</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >=</span> <span style="color: #009900; font-weight: bold;" >null</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	<span style="color: #b1b100;" >return</span> <span style="color: #0000ff;" >'
&lt;div class=&quot;dropcap&quot;&gt;'</span><span style="color: #339933;" >.</span><span style="color: #000088;" >$content</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&lt;/div&gt;
;'</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'dropcap'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'dropcap'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>The CSS:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
</pre></td><td class="code" ><pre class="css"  style="font-family:monospace;" ><span style="color: #6666ff;" >.dropcap</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;" >block</span><span style="color: #00AA00;" >;</span>
<span style="color: #000000; font-weight: bold;" >float</span><span style="color: #00AA00;" >:</span><span style="color: #000000; font-weight: bold;" >left</span><span style="color: #00AA00;" >;</span>
<span style="color: #000000; font-weight: bold;" >font-size</span><span style="color: #00AA00;" >:</span><span style="color: #933;" >50px</span><span style="color: #00AA00;" >;</span>
<span style="color: #000000; font-weight: bold;" >line-height</span><span style="color: #00AA00;" >:</span><span style="color: #933;" >40px</span><span style="color: #00AA00;" >;</span>
<span style="color: #000000; font-weight: bold;" >margin</span><span style="color: #00AA00;" >:</span><span style="color: #cc66cc;" >0</span> <span style="color: #933;" >5px</span> <span style="color: #cc66cc;" >0</span> <span style="color: #cc66cc;" >0</span><span style="color: #00AA00;" >;</span>
<span style="color: #00AA00;" >&#125;</span></pre></td></tr></table></div>

<p>Use it with:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[dropcap]M[/dropcap]auris ut lectus erat. In ...</pre></div></div>

<p><em>Credit for this shortcode goes to <a href="http://www.tuttoaster.com/how-to-use-style-and-implement-wordpress-shortcodes/" >TutToaster</a>.</em></p>
<h3>8 &#8211; Custom Post Type Query</h3>
<p>Let&#8217;s say that you have set up a custom post type called <strong>News</strong> and you wish to display all posts inside that custom post type on a page called <strong>Articles</strong>. You could do it with the code below:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> news_shortcode<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;" >//The Query</span>
	query_posts<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'post_type=news'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #666666; font-style: italic;" >//The Loop</span>
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span> have_posts<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;" >while</span> <span style="color: #009900;" >&#40;</span> have_posts<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >:</span> the_post<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >echo</span>	<span style="color: #0000ff;" >'&lt;h3&gt;&lt;a href=&quot;'</span><span style="color: #339933;" >;</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: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&quot;&gt;'</span><span style="color: #339933;" >;</span> <span style="color: #b1b100;" >echo</span> the_title<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span> <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;/a&gt;&lt;/h3&gt;'</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >echo</span> the_excerpt<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #b1b100;" >endwhile</span><span style="color: #339933;" >;</span> <span style="color: #b1b100;" >else</span><span style="color: #339933;" >:</span>
	<span style="color: #b1b100;" >endif</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;" >//Reset Query</span>
	wp_reset_query<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'news'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'news_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>Then display the news posts on your Articles page by using this shortcode:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[news]</pre></div></div>

<h3>9 &#8211; Display Posts from Category on Page</h3>
<p>Very similar to the shortcode example above, we can also display limited number of posts from within a particular category using a shortcode like this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> category_shortcode<span style="color: #009900;" >&#40;</span> <span style="color: #000088;" >$atts</span> <span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
<span style="color: #990000;" >extract</span><span style="color: #009900;" >&#40;</span>shortcode_atts<span style="color: #009900;" >&#40;</span><span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
	    <span style="color: #0000ff;" >'limit'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'5'</span><span style="color: #339933;" >,</span>
            <span style="color: #0000ff;" >'category'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >''</span><span style="color: #339933;" >,</span>
	<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$atts</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #666666; font-style: italic;" >//The Query</span>
	query_posts<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'category='</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$id</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'posts_per_page='</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$limit</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #666666; font-style: italic;" >//The Loop</span>
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span> have_posts<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;" >while</span> <span style="color: #009900;" >&#40;</span> have_posts<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >:</span> the_post<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >echo</span>	<span style="color: #0000ff;" >'&lt;h3&gt;&lt;a href=&quot;'</span><span style="color: #339933;" >;</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: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&quot;&gt;'</span><span style="color: #339933;" >;</span> <span style="color: #b1b100;" >echo</span> the_title<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span> <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;/a&gt;&lt;/h3&gt;'</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >echo</span> the_excerpt<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #b1b100;" >endwhile</span><span style="color: #339933;" >;</span> <span style="color: #b1b100;" >else</span><span style="color: #339933;" >:</span>
	<span style="color: #b1b100;" >endif</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;" >//Reset Query</span>
	wp_reset_query<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'category'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'category_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>You can list the posts using:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[category id=# limit=5]</pre></div></div>

<p>Just replace <strong>#</strong> with the ID of the category you wish to display.</p>
<h3>10 &#8211; Great Examples of Other Possible Shortcodes</h3>
<p>I&#8217;ve shown you a few examples, both of my own and other&#8217;s creation, now let me give you even more examples of awesome things you could do.</p>
<p>Joen Asmussen of <a href="http://noscope.com" >NoScope.com</a> created a really nifty little shortcode to make a Google PDF Viewer.</p>
<p><a href="http://noscope.com/journal/2010/02/wordpress-trick-create-a-google-viewer-pdf-shortcode?utm_source=twitterfeed&#038;utm_medium=twitter" >Check it out here</a></p>
<p>Jean Baptiste, of <a href="http://www.wprecipes.com" >WP-Recipes</a> created a shortcode to display a &#8220;ReTweet&#8221; or &#8220;TweetMeme&#8221; buttons in your posts. <a href="http://www.wprecipes.com/wordpress-tip-create-a-tweetmeme-retweeet-shortcode" >Find it here</a>.</p>
<p><a href="http://justintadlock.com/" >Justin Tadlock</a> made a great plugin that turns all (or most) WordPress template tags into shortcodes so that they can be used within the post editor. <a href="http://wordpress.org/extend/plugins/template-tag-shortcodes/" >Download the Plugin</a>.</p>
<p>A few weeks ago I wrote a shortcode plugin of my own (sorry, couldn&#8217;t leave myself out!). It&#8217;s a shortcode utility plugin that allows you to insert a variety of message boxes and web buttons via shortcodes (similar to some of the examples I&#8217;ve used above). Check out <a href="http://demo.pippinspages.com/wp-utility-shortcodes/" >WP Utility Shortcodes</a>.</p>
<h3>11 &#8211; Some More Ideas</h3>
<ul>
<li>Use shortcodes for displaying contact forms</li>
<li>use shortcodes for displaying a Google map</li>
<li>Shortcodes to display author bios</li>
<li>A shortcode that outputs all of your social network info</li>
<li>Shortcodes for image galleries</li>
<li>Shortcodes for jQuery image sliders</li>
</ul>
<p>Have you seen any other interesting uses of shortcodes? <strong>Do you make use of them in your site already?</strong></p>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/0rPFivWmmBw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/wordpress/working-with-wordpress-shortcodes/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/wordpress/working-with-wordpress-shortcodes/</feedburner:origLink></item>
		<item>
		<title>How to Edit the WordPress RSS Feed</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/HtIsaGtFkIM/</link>
		<comments>http://www.problogdesign.com/wordpress/how-to-edit-the-wordpress-rss-feed/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 00:00:06 +0000</pubDate>
		<dc:creator>Michael Martin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Feed]]></category>
		<category><![CDATA[Filters]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[Thumbnails]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/?p=5728</guid>
		<description><![CDATA[<img src="http://www.problogdesign.com/wp-content/uploads/2010/08/edit-wordpress-feed.jpg" alt="Edit WordPress Feed" title="Edit WordPress Feed" width="560" height="145" class="alignnone size-full wp-image-5744" />

Ever thought you could make some <strong>improvements to your RSS feed?</strong> Like letting it cover more (or less!) content? Or adding some extra details onto the end of your posts?

In this post, I'm going to show you how to do exactly that.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/08/edit-wordpress-feed.jpg"  alt="Edit WordPress Feed"  title="Edit WordPress Feed"  width="560"  height="145"  class="alignnone size-full wp-image-5744" /></p>
<p>Ever thought you could make some <strong>improvements to your RSS feed?</strong> Like letting it cover more (or less!) content? Or adding some extra details onto the end of your posts?</p>
<p>In this post, I&#8217;m going to show you how to do exactly that. Here&#8217;s what we&#8217;ll be covering:</p>
<ul class="nospace" >
<li>How to include both posts <strong>and pages</strong> in your feeds.</li>
<li>How to add <strong>thumbnails</strong> to your feeds.</li>
<li>How to <strong>exclude posts </strong>with a certain tag.</li>
<li>Set <strong>how many posts</strong> appear in your feed (Without affecting the rest of your site).</li>
<li>How to show only posts from a <strong>certain category</strong>.</li>
<li>How to <strong>add content to the end </strong>of each post (e.g. link to your <strong>latest featured post</strong>).</li>
</ul>
<p>All of this is going to take place in the<strong> functions.php file </strong>of your theme. If your theme doesn&#8217;t have one, just create a file in your theme&#8217;s folder with that name and let&#8217;s get to it! (Make sure all of this code goes between the opening <?php and closing ?> tag in the file)</p>
<h2>Include Pages in WordPress Feed</h2>
<p>What we will do is add a filter to WordPress when it is searching for posts. The filter is going to check if the posts are for a feed, and if they are, it&#8217;s going to <strong>adjust the query</strong> to include both posts and pages.</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> feedFilter<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_feed</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><span style="color: #0000ff;" >'any'</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;" >'feedFilter'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<p>If you wanted <strong>to show only pages</strong>, then you could change the word &#8216;any&#8217; to &#8216;page&#8217; (or to the name of any custom post types you&#8217;ve created).</p>
<p>You may want to be more specific and <strong>only show top level pages</strong>. In that case, you could use this code with an extra line to show only top level pages:</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> feedFilter<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_feed</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><span style="color: #0000ff;" >'any'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</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_parent'</span><span style="color: #339933;" >,</span><span style="color: #0000ff;" >'0'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		<span style="color: #009900;" >&#125;</span>
	<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$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;" >'feedFilter'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<h2>Add Thumbnails to RSS Feed</h2>
<p>The process this time is slightly different. Again we&#8217;re going to add a filter to the query and test if the page is for an RSS feed. This time<strong> we won&#8217;t adjust the query</strong> though (We&#8217;ll return it exactly as it was), but we will add a filter to the_content (i.e. the content of your posts).</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> feedFilter<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_feed</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
		add_filter<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'the_content'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'feedContentFilter'</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;" >'feedFilter'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;" >function</span> feedContentFilter<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$content</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	<span style="color: #000088;" >$thumbId</span> <span style="color: #339933;" >=</span> get_post_thumbnail_id<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #b1b100;" >if</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$thumbId</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
		<span style="color: #000088;" >$img</span> <span style="color: #339933;" >=</span> wp_get_attachment_image_src<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$thumbId</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		<span style="color: #000088;" >$image</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >'&lt;img align=&quot;left&quot; src=&quot;'</span><span style="color: #339933;" >.</span> <span style="color: #000088;" >$img</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >0</span><span style="color: #009900;" >&#93;</span> <span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&quot; alt=&quot;&quot; width=&quot;'</span><span style="color: #339933;" >.</span> <span style="color: #000088;" >$img</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >1</span><span style="color: #009900;" >&#93;</span> <span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&quot; height=&quot;'</span><span style="color: #339933;" >.</span> <span style="color: #000088;" >$img</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >2</span><span style="color: #009900;" >&#93;</span> <span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&quot; /&gt;'</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >echo</span> <span style="color: #000088;" >$image</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
&nbsp;
	<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$content</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span></pre></div></div>

<p>We&#8217;re using a slightly roundabout way of getting the thumbnail image so that we can add the <em>align=&quot;left&quot;</em> part. A lot of feed readers strip out inline CSS, but using the old-fashioned align property should work. And of course, if you don&#8217;t <strong>want your images aligned to the left</strong>, just take out the <em>align=&quot;left&quot;</em> altogether!</p>
<p>You can use that code to get any size of thumbnail as well, e.g. let&#8217;s say you had added this line to your functions.php file to define a special thumbnail size just for feeds:</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" >add_image_size<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'feed'</span><span style="color: #339933;" >,</span> <span style="color: #cc66cc;" >600</span><span style="color: #339933;" >,</span> <span style="color: #cc66cc;" >100</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></pre></div></div>

<p>Then you could adjust the 7th line from the end to read:</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000088;" >$img</span> <span style="color: #339933;" >=</span> wp_get_attachment_image_src<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$thumbId</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'feed'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<h2>How to Exclude Posts With a Certain Tag</h2>
<p>This time we&#8217;re going to do something similar to the first example. We&#8217;ll be using &#8216;set&#8217; to adjust the query object. If you want to read more about what you can do with querys, check out the <a href="http://codex.wordpress.org/Function_Reference/WP_Query" >WP_Query codex page</a>.</p>
<p>The only nuisance is that we have to first <strong>work out the ID of the tag</strong> we want to exclude. To do this, go to <em>Posts > Post Tags</em>, then find the tag you want to exclude and click on it. In your browser&#8217;s address bar, you&#8217;ll see that part of the URL looks like this: <strong>&#038;tag_ID=29</strong></p>
<p>So in that case, 29 is the tag ID.</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> feedFilter<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_feed</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
		<span style="color: #000088;" >$tags</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'29'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</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;" >'tag__not_in'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$tags</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
&nbsp;
	<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$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;" >'feedFilter'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<p>If you wanted to exclude posts from multiple tags, you could list them on the 3rd line, e.g.</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000088;" >$tags</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'29'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'31'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'124'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<h2>Control How Many Posts Appear in the Feed</h2>
<p>In your dashboard, under Settings &gt; Reading, you can set how many posts appear on your site pages and in your feed. However, there may be times when you want to show <strong>more posts in your feed than on your site</strong>.</p>
<p>e.g. your site may look best with just 3 or 4 posts per page, but you&#8217;d definitely want more than that in your feed!</p>
<p>To make that change, just use the code below:</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> feedFilter<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_feed</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;" >'posts_per_page'</span><span style="color: #339933;" >,</span><span style="color: #0000ff;" >'20'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
&nbsp;
	<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$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;" >'feedFilter'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<p>Feel free to change the 20 to <strong>any number</strong> you like!</p>
<h2>Show Posts from Only One Category</h2>
<p>Normal blogs are unlikely to do this, but if you were using WordPress as a CMS, you may want to publish <strong>only posts from your &#8220;blog&#8221; category</strong>. In that case, you would do this:</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> feedFilter<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_feed</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;" >'blog'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
&nbsp;
	<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$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;" >'feedFilter'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<p>And again, you could turn that on its head to <strong>exclude posts from a certain category</strong>. In that case, the 3rd line would be:</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><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;" >'cat'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'-45'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></div></div>

<p>Where 45 is the <strong>ID of the category</strong> (The minus sign must be included as well, otherwise you&#8217;ll end up showing only posts from category 45!).</p>
<h2>Add Content to the End of Each RSS Post</h2>
<p>There are plenty of reason you might want to <strong>add some content</strong> to the end of your RSS posts. In this first example, we&#8217;ll add a simple line that says:</p>
<p> &quot;Thanks for reading, check out <a href="#" >Your Blog name</a> for more WordPress news!&quot;</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> feedFilter<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_feed</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
		add_filter<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'the_content'</span><span style="color: #339933;" >,</span><span style="color: #0000ff;" >'feedContentFilter'</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;" >'feedFilter'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;" >function</span> feedContentFilter<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$content</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	<span style="color: #000088;" >$content</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >'&lt;p&gt;Thanks for reading, check out &lt;a href=&quot;'</span><span style="color: #339933;" >.</span> get_bloginfo<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'url'</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&quot;&gt;'</span><span style="color: #339933;" >.</span> get_bloginfo<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'name'</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&lt;/a&gt; for more WordPress news!&lt;/p&gt;'</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$content</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span></pre></div></div>

<p>Now let&#8217;s do something slightly cooler. Let&#8217;s say that you have a featured content slider on your homepage, or a featured posts list in your sidebar, and you&#8217;ve set it up so that to add posts to either of these, <strong>you tag them with &#8220;featured.&#8221;</strong></p>
<p>In this last example, we&#8217;ll add a <strong>byline to your feed posts</strong> that says:</p>
<p>&quot;Make sure not to miss our latest featured post: <a href="#" >Post Title</a>&quot;</p>
<p>In our feedContentFIlter function this time, we will run a query to get the latest post tagged with featured. We&#8217;ll then use the post object we get back to <strong>insert the post title and address</strong>.</p>

<div class="wp_syntax" ><div class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> feedFilter<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_feed</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
		add_filter<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'the_content'</span><span style="color: #339933;" >,</span><span style="color: #0000ff;" >'feedContentFilter'</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;" >'feedFilter'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;" >function</span> feedContentFilter<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$content</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
&nbsp;
	<span style="color: #000088;" >$args</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
	    <span style="color: #0000ff;" >'numberposts'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #cc66cc;" >1</span><span style="color: #339933;" >,</span>
	    <span style="color: #0000ff;" >'tag'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'featured'</span>
	<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #000088;" >$posts</span> <span style="color: #339933;" >=</span> get_posts<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$args</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #b1b100;" >if</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$posts</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	    <span style="color: #b1b100;" >foreach</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$posts</span> <span style="color: #b1b100;" >as</span> <span style="color: #000088;" >$post</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	        <span style="color: #000088;" >$content</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >'&lt;p&gt;Make sure not to miss our latest featured post: &lt;a href=&quot;'</span><span style="color: #339933;" >.</span> get_permalink<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&quot;&gt;'</span><span style="color: #339933;" >.</span> <span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >post_title</span> <span style="color: #339933;" >.</span><span style="color: #0000ff;" >'&lt;/a&gt;!&lt;/p&gt;'</span><span style="color: #339933;" >;</span>
	    <span style="color: #009900;" >&#125;</span>
	<span style="color: #009900;" >&#125;</span>
&nbsp;
	<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$content</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span></pre></div></div>

<p>You could enhance that however you like, e.g. including some inline CSS to adjust the appearance of the line.</p>
<h2>How Else Could You Edit Your Feed?</h2>
<p>Those are some ideas for what you could do with your feed, but is there <strong>anything else you&#8217;d like to do with it?</strong></p>
<p>Let me know in the comments and if there are any great ideas, <strong>I&#8217;ll show you how to do them!</strong></p>
<p><strong>Update (20th August):</strong> Some commenters have mentioned already that all of these changes are for the main feed. If you&#8217;d like to create a new feed and customize that, check out this <a href="http://www.wprecipes.com/creating-user-defined-rss-feeds-in-wordpress" >post by WordPress Recipes</a> for a good starting point! (You&#8217;ll need to adapt the code samples above slightly though)</p>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/HtIsaGtFkIM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/wordpress/how-to-edit-the-wordpress-rss-feed/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/wordpress/how-to-edit-the-wordpress-rss-feed/</feedburner:origLink></item>
		<item>
		<title>Design Critique: B2Bbloggers.com</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/MMyrpF05PcY/</link>
		<comments>http://www.problogdesign.com/blog-design-reviews/design-critique-b2bbloggers-com/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 16:00:02 +0000</pubDate>
		<dc:creator>Michael Martin</dc:creator>
				<category><![CDATA[Blog Design Reviews]]></category>
		<category><![CDATA[Critique]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/?p=5686</guid>
		<description><![CDATA[<img class="alignnone size-full wp-image-5717" title="B2Bbloggers.com" src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-intro.png" alt="B2Bbloggers.com" width="560" height="145" />

<a href="http://www.b2bbloggers.com/">B2Bbloggers.com</a> is a B2B marketing site that features a lot of guest posts on <strong>B2B marketing</strong>, and highlights a lot of content from around the niche.

We're going to take a look at the site's design today, critique it, and work out <strong>how we could improve it</strong>. As we do hopefully you'll learn to apply this same methodology to your own site.

We'll be working through this design <strong>as a case study,</strong> redesigning each section along the way, so you get to see each item as we rework it, including the full <a href="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-compare.png">before and after design</a>.]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-5717"  title="B2Bbloggers.com"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-intro.png"  alt="B2Bbloggers.com"  width="560"  height="145" /></p>
<p><a href="http://www.b2bbloggers.com/" >B2Bbloggers.com</a> is a B2B marketing site that features a lot of guest posts on <strong>B2B marketing</strong>, and highlights a lot of content from around the niche.</p>
<p>We&#8217;re going to take a look at the site&#8217;s design today, critique it, and work out <strong>how we could improve it</strong>. As we do hopefully you&#8217;ll learn to apply this same methodology to your own site.</p>
<p>We&#8217;ll be working through this design <strong>as a case study,</strong> redesigning each section along the way, so you get to see each item as we rework it, including the full <a href="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-compare.png" >before and after design</a>.</p>
<p>Let&#8217;s start by <a href="http://www.b2bbloggers.com/"  target="_blank" >loading the site</a> in a new tab (Or if you&#8217;re reading later, check out <a href="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-bloggers.png" >this image of the site</a> as it was at this time).</p>
<h2>Issues With the Current Site</h2>
<p>The following 4 are the issues mentioned by Jeremy (the owner of B2Bbloggers) when he asked for the review:</p>
<ul>
<li>Increase subscribers.</li>
<li>Insert categories/archives.</li>
<li>Insert popular posts.</li>
<li>Better use of footer.</li>
</ul>
<p>We&#8217;ll bear those in mind as we go to work on the site later, but let&#8217;s see what other possible issues we can find ourselves. The core areas that I&#8217;d like to improve on are:</p>
<ul>
<li><strong>Heavyset Appearance</strong> -The current colors, lack of spacing, large blocks of text give the site quite a heavy appearance. No single individual element is to blame, but we&#8217;ll see what we can do to air things up a little.</li>
<li><strong><img class="alignright"  title="Avatar/Vote Icons"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b1.png"  alt="Avatar/Vote Icons"  width="164"  height="239" /></strong><strong>Confusion </strong>- The site attempts to do quite a lot (A lot of its own blog posts, but also feeds from other websites, two separate Twitter streams, and a Google Custom Search Engine for a number of B2B sites). It makes for a great set of resources for visitors, but a more unified appearance and clearer sectioning may make it easier to follow.</li>
<li><strong>Clutter</strong> &#8211; Certain areas of the site feel cluttered (Like the avatar/votes downside the posts), and others just need a little work (Like the pixelated social icons). We&#8217;ll sort these out as we go along.</li>
</ul>
<p>With those 7 items in mind, let&#8217;s get to work!</p>
<h2>The Header</h2>
<p>We&#8217;ll start at the top. The header is relatively clean and the navigation bar works well.</p>
<p><a href="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-oldheader.png" ><img class="alignnone size-full wp-image-5695"  title="Current Header"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-oldheader-small.png"  alt="Current Header"  width="560"  height="111" /></a><br/>
(Click to see full size)</p>
<p>It&#8217;s a little bland though. You could hire a graphic designer to create something much more memorable, but a few simple tweaks could go a long way in the meantime.</p>
<p>We&#8217;ll start by changing from the slightly faded blues,<strong> to stronger variants</strong>. After that, we&#8217;ll do a little cleanup.</p>
<p>The &#8220;CrowdsourcedFRD&#8221; link is a bit of a mystery. The trouble is that with no further information than that, very few people are going to click through to it. In essence, the link is asking for feedback on the site. Online,<strong> the clearer things are, the better</strong>. So let&#8217;s rename that.</p>
<p>To help declutter the header slightly more, we&#8217;re going to give your <strong>logo some extra room to breathe</strong>. We&#8217;ll start by moving the navigation links above, over to the right (Where they&#8217;ll work every bit as well). We&#8217;ll also stretch out the header slightly to give the same padding above and below it.</p>
<p>Last of all, we&#8217;ll fix up the borders on the <strong>search form</strong>, bring some of the logo&#8217;s orange into it (It&#8217;s been used so rarely in the site) and move the text inside the search bar (Where some <a href="http://www.problogdesign.com/how-to/dynamic-search-bar-text-with-javascript/" >simple JavaScript</a> can make it disappear when a user clicks).</p>
<p>Nothing complex there, and let&#8217;s see how it looks now? (click to see in full)</p>
<p><a href="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-newheader.png" ><img class="alignnone size-full wp-image-5693"  title="New Header"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-newheader-small.png"  alt="New HEader"  width="560"  height="118" /></a></p>
<h2>The Content</h2>
<p>We&#8217;ll move down to the core content now. On the homepage, there are three main sections:</p>
<ul>
<li>Latest blog posts.</li>
<li>Links from other blogs.</li>
<li>Embedded tweets from B2B marketers.</li>
</ul>
<p>We&#8217;ll start at the top, with the latest blog posts. Currently, the posts are displayed one after the other <strong>with no images</strong> (Except the featured post). The only visual content comes from the author avatars, though they have to fight against the large Twitter and Facebook buttons.</p>
<p>We want to <strong>break up the flow of text/gaps/posts</strong> into something more catchy to look at, to encourage people to scan more of your posts and hopefully click on one. Using images in your content is the ideal way to do this, but it can be difficult (Especially if you have a lot of guest authors like this!).</p>
<p>What we can do instead is <strong>make the layout of the post itself into your visually grabbing element</strong>. Instead of having just paragraphs of text and headers on plain, empty backgrounds, we will try setting each post into its own box. With some simple design touches, we can make that plain text much more appealing.</p>
<p><img class="alignnone size-full wp-image-5699"  title="Homepage Boxes"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-boxes.png"  alt="Homepage Boxes"  width="560"  height="332" /></p>
<p>Now it doesn&#8217;t matter that there is a lack of images, we&#8217;ve worked around it.</p>
<p><img class="alignright size-full wp-image-5701"  title="b2b-pagination"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-pagination.png"  alt=""  width="170"  height="50" />Next we want to include the pagination. There is no need to do anything fancy; just simple, clean numbers that <strong>blend in well with the rest of the page</strong>.</p>
<p>Below the latest blog posts section, the author has included a <strong>list of blogs from his niche</strong>, with links to their latest posts. The layout to use for each blog&#8217;s section is clear; our <strong>box designs from earlier are perfect </strong>for this (We can replace the avatars with the site favicon, and everything else remains the same).</p>
<p>We do need to create a separator between the blog posts and this section though, along with some explanation of what these feeds are. A title/subtitle is the obvious solution for that, but if we think back to our client&#8217;s original goal, <strong>to increase RSS subscribers</strong>, there is an opportunity for us here.</p>
<p>The homepage has been sliced into two clear sections so far. <strong>We need a clear separation between the two anyway</strong>, so why not insert an ad for your RSS feed? (This sort of location works great for actual adverts, so there&#8217;s no reason not to try it out for an ad of our own!).</p>
<p>Beneath that, we can then insert a simple title, and the blog posts below. Let&#8217;s see how it looks (Click for full-size):</p>
<p><a href="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-home-rss.png" ><img class="alignnone size-full wp-image-5704"  title="RSS Ad"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-home-rss-small.png"  alt="RSS Ad"  width="560"  height="285" /></a></p>
<p>One thing to point out is that I have been consistently using 20px of spacing between sections in this design. That is to give the design much more whitespace, relieving the heavyset issue I mentioned at the top. The exception is the spacing between the RSS ad and the header, which is 40px. When I set it at 20, the ad dominated the title, but setting it at 40 set it apart. There&#8217;s <strong>no reason not to bend rules like this when it&#8217;s warranted.</strong></p>
<p>The final section of the current homepage is a list of 10 tweets from a Twitter list. The idea is great, but they look somewhat poor on the homepage I find. For example, they currently show a list of 10 FollowFriday tweets (So basically, <strong>just dozens of @names!</strong>), and most of them are from the one person so the avatar is just repeated.</p>
<p>The idea of promoting others is a great one, but given that we&#8217;re going to be enhancing the footer later, we can<strong> experiment with moving the tweets to there</strong>. If the client has a good reason for having them on the homepage, there&#8217;s no reason we can&#8217;t move them back later.</p>
<h2>Sidebar</h2>
<p>The current <strong>sidebar is quite cluttered</strong>, and lacks any real unity between the different sections. In particular, there is a section where ads and colored widgets are mixed together. I want to break this up to make it less likely for users to simply block out that whole section.</p>
<p>If we start at the top, we&#8217;ll being with the social connection box. The current one has a fair amount of writing, small signup forms, and even pixelated icons. We will take out the fluff, <strong>leaving only the calls to action</strong> for visitors.</p>
<p>In terms of the design; because the rest of the sidebar will be in boxes, we can highlight this section by having it sit right on the background. As for the email subscription form, we will <strong>use the search form design from right above it</strong> verbatim.</p>
<p>In the image below, you can see the original on the left, and the newer version on the right.</p>
<p><img class="alignnone size-full wp-image-5707"  title="Social Widget"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-social.png"  alt="Social Widget"  width="560"  height="124" /></p>
<p>Working down the sidebar, we will <strong>add content as we need it</strong>. We&#8217;ll start by listing the categories (One of the client&#8217;s wishes), followed by an advert (In the same location it currently is), with popular posts beneath that (Another of the client&#8217;s wishes, and lastly, their Twitter ad and stream (The least important of the modules, so it comes at the end).</p>
<p>Design-wise, the ads are untouched of course. The category lists and popular posts section will both use our box design from the homepage. The big change with the Twitter widget is that we will embed the tweets ourselves, allowing us to <strong>use a clean box design as well</strong>, rather than the intrusive Twitter widget currently used.</p>
<p>Using our boxes for our footer content makes it easy to add more widgets in the future. Just re-use what&#8217;s already there.</p>
<h2>Footer</h2>
<p>We&#8217;re nearing the end now, the final section to work on is the footer.</p>
<p>When I listed the sidebar widgets, I left out two of the sections of the current sidebar; the &#8220;About&#8221; box, and the links to various parts of the site. By doing that, we <strong>cut down on the clutter of the sidebar</strong> by taking out content that will fit every bit as well in the footer.</p>
<p>We will use an expanded footer, split into three sections (<strong>Lining up with the 3 columns</strong> of content above). We can group the site links into one &#8220;Get Involved!&#8221; section, and because those links are important, we&#8217;ll put that first.</p>
<p>We will add the &#8220;About&#8221; section to the end, as that is somewhat of a <strong>standard location for that content</strong>.</p>
<p>And that leaves the central section for the <strong>marketing tweets</strong> I left out of the homepage.</p>
<p>In terms of the design, we will tie in with the rest of the site&#8217;s design of course. In the header, I used a <strong>slight gradient for the dark navy section</strong>. We can re-use that same gradient (The one I&#8217;ve also been using on the box links, and the RSS advert) for our background. This makes it clearly stand out as separated from the content and sidebar.</p>
<p>The rest of the footer design is then kept minimal. We will use a simple separating line between each one, white text with orange links (The <strong>same colors we&#8217;ve used across the site</strong>, all taken from the logo), and because both the Twitter and About sections have an image, we&#8217;ll add the site&#8217;s Twitter logo to the &#8220;Get Involved!&#8221; section as well.</p>
<p>Here goes! (Click the image to see it in full)</p>
<p><a href="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-footer.png" ><img class="alignnone size-full wp-image-5710"  title="Footer Design"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-footer-small.png"  alt="Footer Design"  width="560"  height="150" /></a></p>
<p>And that completes our design! We&#8217;ve taken the current site, kept all of its content and its &#8220;feel&#8221;, but remade the layout to remove the clutter, add some extra visual appeal, and play to the site&#8217;s strengths (e.g. highlighting the social connection options, and working with text not images).</p>
<p>To finish off, click below to <a href="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-compare.png" >see the completed design</a>, <strong>side-by-side </strong>with the original!</p>
<p><a href="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-compare.png" ><img class="alignnone size-full wp-image-5713"  title="Compare"  src="http://www.problogdesign.com/wp-content/uploads/2010/08/b2b-compare-small.png"  alt="Compare"  width="560"  height="145" /></a></p>
<p>Now it&#8217;s your turn! If <a href="http://www.b2bbloggers.com/" >B2Bbloggers</a> were your site, <strong>what would you do with it? </strong>Where would you put those tweets? Would you have kept more elements of the current design that I did?</p>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/MMyrpF05PcY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/blog-design-reviews/design-critique-b2bbloggers-com/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/blog-design-reviews/design-critique-b2bbloggers-com/</feedburner:origLink></item>
		<item>
		<title>MyBiz Theme for WordPress Discount Code</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/VE_5Imemu2w/</link>
		<comments>http://www.problogdesign.com/wordpress/mybiz-theme-for-wordpress-discount-code/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 16:00:14 +0000</pubDate>
		<dc:creator>Michael Martin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[PliablePress]]></category>
		<category><![CDATA[wordpress themes]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/?p=5673</guid>
		<description><![CDATA[<a href="http://www.pliablepress.com/themes/mybiz/"><img src="http://www.problogdesign.com/wp-content/uploads/2010/08/pbd-mybiz1.jpg" alt="MyBiz" title="MyBiz" width="560" height="145" class="alignnone size-full wp-image-5674" /></a>

Over on <a href="http://www.pliablepress.com/">PliablePress</a>, we've released our newest WordPress theme. <a href="http://www.pliablepress.com/themes/mybiz/">MyBiz</a> is designed for modern businesses who <strong>don't want the "faceless-company" approach</strong> that customers are used to receiving.

It's vibrant, colorful (You even get 5 color schemes to choose from!) and yet still professional and well organized. Most of all, we've put an extreme amount of care into the homepage, giving you 3 different ways to ensure your best content is highlighted and that your <strong>visitors go to the pages you want them to see</strong>.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pliablepress.com/themes/mybiz/" ><img src="http://www.problogdesign.com/wp-content/uploads/2010/08/pbd-mybiz1.jpg"  alt="MyBiz"  title="MyBiz"  width="560"  height="145"  class="alignnone size-full wp-image-5674" /></a></p>
<p>Over on <a href="http://www.pliablepress.com/" >PliablePress</a>, we&#8217;ve released our newest WordPress theme. <a href="http://www.pliablepress.com/themes/mybiz/" >MyBiz</a> is designed for modern businesses who <strong>don&#8217;t want the &#8220;faceless-company&#8221; approach</strong> that customers are used to receiving.</p>
<p>It&#8217;s vibrant, colorful (You even get 5 color schemes to choose from!) and yet still professional and well organized. Most of all, we&#8217;ve put an extreme amount of care into the homepage, giving you 3 different ways to ensure your best content is highlighted and that your <strong>visitors go to the pages you want them to see</strong>.</p>
<p>Check out the walkthrough video below showing you some of the features of MyBiz that you may not notice at first, as well as <strong>how easy it is to control all of your homepage content</strong> with our beginner-friendly control panel. Or better yet, check out the <a href="http://pliablepress.com/demo/mybiz/" >live demo site</a>.</p>
<p>If you <a href="http://www.pliablepress.com/members/signup.php?price_group=8" >buy MyBiz</a> before this Saturday, <strong>you can save an extra $15</strong>. Just use this coupon code on the signup page (For either MyBiz, or the Plus+ membership!): MYBIZ15</p>
<p>To see more (Or get the theme for yourself!), check out the <a href="http://www.pliablepress.com/themes/mybiz/" >MyBiz page</a> on PliablePress.</p>
<p><object width="560"  height="340" ><param name="movie"  value="http://www.youtube.com/v/5HkqwHPv1ik&amp;hl=en_US&amp;fs=1?rel=0" /></param><param name="allowFullScreen"  value="true" /></param><param name="allowscriptaccess"  value="always" /></param><embed src="http://www.youtube.com/v/5HkqwHPv1ik&amp;hl=en_US&amp;fs=1?rel=0"  type="application/x-shockwave-flash"  allowscriptaccess="always"  allowfullscreen="true"  width="560"  height="340" ></embed></object></p>
<p>Let me know <strong>what you think of the theme</strong> in the comments, I&#8217;d love to hear your thoughts!</p>
<h2>BundleHunt Released!</h2>
<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/08/WDD-thumb.jpg"  alt=""  title="WDD-thumb"  width="200"  height="160"  class="alignright size-full wp-image-5678" /> <a href="http://bundlehunt.com/" >BundleHunt</a>, the latest project by the awesome Noura Yehia (Noupe and DevSnippets) <a href="http://bundlehunt.com/about" >and friends</a> went live yesterday.</p>
<p>They&#8217;ve collected together 12 great design-related products and bundled them together for a single, very-cheap price of $49.</p>
<p>Make sure you have a look to see if it catches your eye (I&#8217;ve been eyeing <a href="http://www.marketcircle.com/billings/" >Billings</a> up for a while now, so I&#8217;ll definitely be getting it!). And at the very least, it&#8217;s worth loading just to see the stunning web design.</p>
<p>Anything there appeal to you too?</p>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/VE_5Imemu2w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/wordpress/mybiz-theme-for-wordpress-discount-code/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/wordpress/mybiz-theme-for-wordpress-discount-code/</feedburner:origLink></item>
		<item>
		<title>How To Write a Restricted Content Plugin</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/BfQ-fyFksMo/</link>
		<comments>http://www.problogdesign.com/wordpress/how-to-write-a-restricted-content-plugin/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 16:00:44 +0000</pubDate>
		<dc:creator>Pippin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[restricted content]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[wordpress plugin]]></category>
		<category><![CDATA[wp plugin]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/?p=5630</guid>
		<description><![CDATA[<a href="http://www.problogdesign.com/wp-content/uploads/2010/07/Restricted-Content-plugin.jpg"><img src="http://www.problogdesign.com/wp-content/uploads/2010/07/Restricted-Content-plugin.jpg" alt="Restrict content to registered users" title="Restricted-Content-plugin" width="560" height="145" class="alignnone size-full wp-image-5658" /></a>

There are a lot of sites out there, particularly digital education sites, such as <a href="http://net.tutsplus.com/">Net Tuts</a> and <a href="http://www.blendercookie.com/">Blender Cookie</a>, that push out a lot of "premium" content that is only accessible to registered users.

In this tutorial, I'm going to show you some of the basics of writing a WordPress plugin from scratch that will allow you to restrict content on your site to registered users. You will be able to <strong>restrict complete pages / posts</strong> by clicking <strong>a check box</strong> or just sections of content using <strong>WordPress <a href="http://codex.wordpress.org/Shortcode_API">shortcodes</a></strong>.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.problogdesign.com/wp-content/uploads/2010/07/Restricted-Content-plugin.jpg" ><img src="http://www.problogdesign.com/wp-content/uploads/2010/07/Restricted-Content-plugin.jpg"  alt="Restrict content to registered users"  title="Restricted-Content-plugin"  width="560"  height="145"  class="alignnone size-full wp-image-5658" /></a></p>
<p>There are a lot of sites out there, particularly digital education sites, such as <a href="http://net.tutsplus.com/" >Net Tuts</a> and <a href="http://www.blendercookie.com/" >Blender Cookie</a>, that push out a lot of &#8220;premium&#8221; content that is only accessible to registered users.</p>
<p>In this tutorial, I&#8217;m going to show you some of the basics of writing a WordPress plugin from scratch that will allow you to restrict content on your site to registered users. You will be able to <strong>restrict complete pages / posts</strong> by clicking <strong>a check box</strong> or just sections of content using <strong>WordPress <a href="http://codex.wordpress.org/Shortcode_API" >shortcodes</a></strong>.</p>
<p><em>Note: I will not be showing how to create a paid membership system, or how to integrate this plugin into a paid membership system, such as <a href="http://www.amember.com/p/" >aMember</a>. This plugin will deal with choosing which content is restricted, but not how users register. It will use the default WordPress user roles: Administrator, Editor, Author, Subscriber, and None</em>.</p>
<h3>1 &#8211; Getting Started &#8211; The Plugin Basics</h3>
<p>WordPress plugin development is very similar to theme development and can employ many of the same tricks to achieve the end goal.</p>
<p>If you are not at all familiar with WordPress plugin development, I recommend you read <a href="http://codex.wordpress.org/Writing_a_Plugin" >Writing a WordPress Plugin</a> from the WordPress codex.</p>
<h3>2 &#8211; The Plugin Header</h3>
<p>The first thing to do, once we&#8217;re ready to start writing our plugin, is to create a new file called <strong>restrict_content.php</strong> and to enter all of the plugin&#8217;s necessary meta data, such as name, author, description, url, etc.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >&lt;?php</span>
<span style="color: #666666; font-style: italic;" >/*
Plugin Name: Restrict Content
Plugin URI: http://pippinspages.com/freebies/restricted-content-plugin-free/
Description: Restrict Content to registered users only.
Version: 1.0
Author: Pippin Williamson
Author URL: http://pippinspages.com
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;" >?&gt;</span></pre></td></tr></table></div>

<p>If you upload this file to your <em>wp-content/plugins</em> directory and click <em>Activate</em> from the WordPress plugins menu, the plugin will activate fine, though it won&#8217;t actually do anything at this time.</p>
<h3>3 &#8211; Create the Shortcode</h3>
<p>Now it&#8217;s time to begin really writing the plugin.</p>
<p>First we are going to create a function that will allow us to use WordPress shortcodes to restrict sections of content like this:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[restrict] . . . this is restricted to logged in users . . . [/restrict]</pre></div></div>

<p>Paste this below the plugin meta info we entered earlier:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> restrict_shortcode<span style="color: #009900;" >&#40;</span> <span style="color: #000088;" >$atts</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$content</span> <span style="color: #339933;" >=</span> <span style="color: #009900; font-weight: bold;" >null</span> <span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
   <span style="color: #990000;" >extract</span><span style="color: #009900;" >&#40;</span> shortcode_atts<span style="color: #009900;" >&#40;</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
      <span style="color: #0000ff;" >'userlevel'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'none'</span><span style="color: #339933;" >,</span>
      <span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$atts</span> <span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
      <span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$userlevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'admin'</span> <span style="color: #339933;" >&amp;&amp;</span> current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'switch_themes'</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span>
      <span style="color: #009900;" >&#123;</span>
      	<span style="color: #b1b100;" >return</span> do_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$content</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
      <span style="color: #009900;" >&#125;</span>
      <span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$userlevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'editor'</span> <span style="color: #339933;" >&amp;&amp;</span> current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'moderate_comments'</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span>
      <span style="color: #009900;" >&#123;</span>
      	<span style="color: #b1b100;" >return</span> do_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$content</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
      <span style="color: #009900;" >&#125;</span>
      <span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$userlevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'author'</span> <span style="color: #339933;" >&amp;&amp;</span> current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'upload_files'</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span>
      <span style="color: #009900;" >&#123;</span>
      	<span style="color: #b1b100;" >return</span> do_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$content</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
      <span style="color: #009900;" >&#125;</span>
      <span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$userlevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'subscriber'</span> <span style="color: #339933;" >&amp;&amp;</span> current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'read'</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span>
      <span style="color: #009900;" >&#123;</span>
	      	<span style="color: #b1b100;" >return</span> do_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$content</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	  <span style="color: #009900;" >&#125;</span>
	  <span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$userlevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'none'</span> <span style="color: #339933;" >&amp;&amp;</span> is_user_logged_in<span style="color: #009900;" >&#41;</span>
      <span style="color: #009900;" >&#123;</span>
	      	<span style="color: #b1b100;" >return</span> do_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$content</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	  <span style="color: #009900;" >&#125;</span>
      <span style="color: #b1b100;" >else</span> <span style="color: #b1b100;" >return</span> <span style="color: #0000ff;" >'&lt;span style=&quot;color: red;&quot;&gt;Some content is only viewable by '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$userlevel</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'s&lt;/span&gt;'</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'restrict'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'restrict_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>What does this code do?</p>
<p>It first creates a place for us to store options (in the variable <em>$atts</em>), and a place to store the content contained within the shortcode (in the variable <em>$content</em>).</p>
<p>Next, an option is created called <em>userlevel</em> and it is given a default value of <em>none</em>. This option allows us to define which users will be able to see the content inside of the shortcode.</p>
<p>When loading the content, every visitor&#8217;s user status must be checked, and only to those whom have sufficient privileges will the content be displayed. This check is done like this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$userlevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'admin'</span> <span style="color: #339933;" >&amp;&amp;</span> current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'switch_themes'</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
  <span style="color: #b1b100;" >return</span> do_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$content</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span></pre></td></tr></table></div>

<p>This will check whether the user level is set to admin and if the current user has the ability to switch themes. If both of these are true, the content contained in the shortcode will be displayed. If one of the above checks is <em>not</em> true, then this happens:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #b1b100;" >else</span> <span style="color: #b1b100;" >return</span> <span style="color: #0000ff;" >'&lt;span style=&quot;color: red;&quot;&gt;Some content is only viewable by '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$userlevel</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'s&lt;/span&gt;'</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>Which will display the message: <span style="color: red;" >Some content is only viewable by admins</span></p>
<p>These two checks are done for every user level.</p>
<p>Lastly, we need to make the shortcode available for use by doing this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" >add_shortcode<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'restrict'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'restrict_shortcode'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>Now we are able to use something like this in our posts / pages:</p>

<div class="wp_syntax" ><div class="code" ><pre class="html4strict"  style="font-family:monospace;" >[restrict userlevel=&quot;editor&quot;] . . . this is restricted to logged in users . . . [/restrict]</pre></div></div>

<p>The available options are:</p>
<ul>
<li>admin</li>
<li>editor</li>
<li>author</li>
<li>subscriber</li>
<li>none <em>(this is the same as using just [restrict] . . . [/restrict] )</em></li>
</ul>
<h3>4 &#8211; Creating the Meta Box</h3>
<p>The next step is to add an option to all posts / pages that will allow us to restrict the entire post / page. This is much better than simply wrapping shortcodes around our entire post / page, even though it would accomplish the same thing.</p>
<p>We will do this by adding a custom meta box to our editor screen. This will be done with multiple functions, all pasted just below the code we already have in our <strong>restrict_content.php</strong> plugin file.</p>
<p>The first function defines all of the options for our meta box:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #666666; font-style: italic;" >//custom meta boxes</span>
<span style="color: #000088;" >$prefix</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >'rc'</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #000088;" >$meta_box</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
    <span style="color: #0000ff;" >'id'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'rcMetaBox'</span><span style="color: #339933;" >,</span>
    <span style="color: #0000ff;" >'title'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'Restrict this content'</span><span style="color: #339933;" >,</span>
    <span style="color: #0000ff;" >'context'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'normal'</span><span style="color: #339933;" >,</span>
    <span style="color: #0000ff;" >'priority'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'high'</span><span style="color: #339933;" >,</span>
    <span style="color: #0000ff;" >'fields'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
        <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
            <span style="color: #0000ff;" >'name'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'User Level'</span><span style="color: #339933;" >,</span>
            <span style="color: #0000ff;" >'id'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$prefix</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'UserLevel'</span><span style="color: #339933;" >,</span>
            <span style="color: #0000ff;" >'type'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'select'</span><span style="color: #339933;" >,</span>
            <span style="color: #0000ff;" >'desc'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'Choose the user level that can see this page / post'</span><span style="color: #339933;" >,</span>
            <span style="color: #0000ff;" >'options'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'None'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'Administrator'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'Editor'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'Author'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'Subscriber'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
            <span style="color: #0000ff;" >'std'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'None'</span>
        <span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
        <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span>
        	<span style="color: #0000ff;" >'name'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'Hide from Feed?'</span><span style="color: #339933;" >,</span>
        	<span style="color: #0000ff;" >'id'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$prefix</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'FeedHide'</span><span style="color: #339933;" >,</span>
        	<span style="color: #0000ff;" >'type'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'checkbox'</span><span style="color: #339933;" >,</span>
        	<span style="color: #0000ff;" >'desc'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >'HIde the excerpt of this post / page from the Feed?'</span><span style="color: #339933;" >,</span>
        	<span style="color: #0000ff;" >'std'</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >''</span>
     	<span style="color: #009900;" >&#41;</span>
    <span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>We have now created an option for choosing the user level to which we&#8217;d like to restrict the content, and an option to hide the content from being displayed (even as an excerpt) in the feed.</p>
<p>Now let&#8217;s actually make the meta box display on the editor screen:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #666666; font-style: italic;" >// Add meta box</span>
<span style="color: #000000; font-weight: bold;" >function</span> rcAddMetaBoxes<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;" >global</span> <span style="color: #000088;" >$meta_box</span><span style="color: #339933;" >;</span>
	<span style="color: #b1b100;" >foreach</span> <span style="color: #009900;" >&#40;</span><span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'post'</span><span style="color: #339933;" >,</span><span style="color: #0000ff;" >'page'</span><span style="color: #009900;" >&#41;</span> <span style="color: #b1b100;" >as</span> <span style="color: #000088;" >$type</span><span style="color: #009900;" >&#41;</span>     
    add_meta_box<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$meta_box</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$meta_box</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'title'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'rcShowMetaBox'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$type</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$meta_box</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'context'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$meta_box</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'priority'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_action<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'admin_menu'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'rcAddMetaBoxes'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>Inside of the <em>add_meta_box</em> command, we are calling all of the options we defined above.</p>
<p>The next step is to make a function that controls how the meta options are displayed. This next function is called by the third variable (<em>rcShowMetaBox</em>) in the above function.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #666666; font-style: italic;" >// Callback function to show fields in meta box</span>
<span style="color: #000000; font-weight: bold;" >function</span> rcShowMetaBox<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;" >global</span> <span style="color: #000088;" >$meta_box</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$post</span><span style="color: #339933;" >;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;" >// Use nonce for verification</span>
    <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;input type=&quot;hidden&quot; name=&quot;rcMetaNonce&quot; value=&quot;'</span><span style="color: #339933;" >,</span> wp_create_nonce<span style="color: #009900;" >&#40;</span><span style="color: #990000;" >basename</span><span style="color: #009900;" >&#40;</span><span style="color: #009900; font-weight: bold;" >__FILE__</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&quot; /&gt;'</span><span style="color: #339933;" >;</span>
&nbsp;
    <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;table class=&quot;form-table&quot;&gt;'</span><span style="color: #339933;" >;</span>
&nbsp;
    <span style="color: #b1b100;" >foreach</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$meta_box</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'fields'</span><span style="color: #009900;" >&#93;</span> <span style="color: #b1b100;" >as</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
        <span style="color: #666666; font-style: italic;" >// get current post meta data</span>
        <span style="color: #000088;" >$meta</span> <span style="color: #339933;" >=</span> get_post_meta<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #009900; font-weight: bold;" >true</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
        <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;tr&gt;'</span><span style="color: #339933;" >,</span>
                <span style="color: #0000ff;" >'&lt;th style=&quot;width:20%&quot;&gt;&lt;label for=&quot;'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&quot;&gt;'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'name'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&lt;/label&gt;&lt;/th&gt;'</span><span style="color: #339933;" >,</span>
                <span style="color: #0000ff;" >'&lt;td&gt;'</span><span style="color: #339933;" >;</span>
        <span style="color: #b1b100;" >switch</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'type'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
            <span style="color: #b1b100;" >case</span> <span style="color: #0000ff;" >'select'</span><span style="color: #339933;" >:</span>
                <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;select name=&quot;'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&quot; id=&quot;'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&quot;&gt;'</span><span style="color: #339933;" >;</span>
                <span style="color: #b1b100;" >foreach</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'options'</span><span style="color: #009900;" >&#93;</span> <span style="color: #b1b100;" >as</span> <span style="color: #000088;" >$option</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
                    <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;option'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$meta</span> <span style="color: #339933;" >==</span> <span style="color: #000088;" >$option</span> ? <span style="color: #0000ff;" >' selected=&quot;selected&quot;'</span> <span style="color: #339933;" >:</span> <span style="color: #0000ff;" >''</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&gt;'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$option</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&lt;/option&gt;'</span><span style="color: #339933;" >;</span>
                <span style="color: #009900;" >&#125;</span>
                <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;/select&gt;'</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: #0000ff;" >'checkbox'</span><span style="color: #339933;" >:</span>
                <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;input type=&quot;checkbox&quot; name=&quot;'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&quot; id=&quot;'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&quot;'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$meta</span> ? <span style="color: #0000ff;" >' checked=&quot;checked&quot;'</span> <span style="color: #339933;" >:</span> <span style="color: #0000ff;" >''</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >' /&gt;'</span><span style="color: #339933;" >;</span>
                <span style="color: #b1b100;" >break</span><span style="color: #339933;" >;</span>
        <span style="color: #009900;" >&#125;</span>
        <span style="color: #b1b100;" >echo</span>     <span style="color: #0000ff;" >'&lt;td&gt;'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'desc'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'&lt;/td&gt;&lt;td&gt;'</span><span style="color: #339933;" >,</span>
            <span style="color: #0000ff;" >'&lt;/tr&gt;'</span><span style="color: #339933;" >;</span>
    <span style="color: #009900;" >&#125;</span>
&nbsp;
    <span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;/table&gt;'</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span></pre></td></tr></table></div>

<p>This will now provide us with a nice layout for our &#8220;restrict content&#8221; options. At the top of this function we have included a hidden input for the nonce verification. This makes sure that no one edits these options who does not have permission.</p>
<p>Finally, we need to have a function to save our data we have inputed. Once again, copy this into <strong>restrict_content.php</strong> beneath all of the code you have already entered.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" > <span style="color: #666666; font-style: italic;" >// Save data from meta box</span>
<span style="color: #000000; font-weight: bold;" >function</span> rcSaveData<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post_id</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
    <span style="color: #000000; font-weight: bold;" >global</span> <span style="color: #000088;" >$meta_box</span><span style="color: #339933;" >;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;" >// verify nonce</span>
    <span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #339933;" >!</span>wp_verify_nonce<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$_POST</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'rcMetaNonce'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #990000;" >basename</span><span style="color: #009900;" >&#40;</span><span style="color: #009900; font-weight: bold;" >__FILE__</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
        <span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$post_id</span><span style="color: #339933;" >;</span>
    <span style="color: #009900;" >&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;" >// check autosave</span>
    <span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #990000;" >defined</span><span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'DOING_AUTOSAVE'</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >&amp;&amp;</span> DOING_AUTOSAVE<span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
        <span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$post_id</span><span style="color: #339933;" >;</span>
    <span style="color: #009900;" >&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;" >// check permissions</span>
    <span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'page'</span> <span style="color: #339933;" >==</span> <span style="color: #000088;" >$_POST</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'post_type'</span><span style="color: #009900;" >&#93;</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: #339933;" >!</span>current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'edit_page'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$post_id</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
            <span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$post_id</span><span style="color: #339933;" >;</span>
        <span style="color: #009900;" >&#125;</span>
    <span style="color: #009900;" >&#125;</span> <span style="color: #b1b100;" >elseif</span> <span style="color: #009900;" >&#40;</span><span style="color: #339933;" >!</span>current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'edit_post'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$post_id</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
        <span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$post_id</span><span style="color: #339933;" >;</span>
    <span style="color: #009900;" >&#125;</span>
&nbsp;
    <span style="color: #b1b100;" >foreach</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$meta_box</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'fields'</span><span style="color: #009900;" >&#93;</span> <span style="color: #b1b100;" >as</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
        <span style="color: #000088;" >$old</span> <span style="color: #339933;" >=</span> get_post_meta<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post_id</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #009900; font-weight: bold;" >true</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
        <span style="color: #000088;" >$new</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$_POST</span><span style="color: #009900;" >&#91;</span><span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span>
&nbsp;
        <span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$new</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #000088;" >$new</span> <span style="color: #339933;" >!=</span> <span style="color: #000088;" >$old</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
            update_post_meta<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post_id</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$new</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
        <span style="color: #009900;" >&#125;</span> <span style="color: #b1b100;" >elseif</span> <span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >''</span> <span style="color: #339933;" >==</span> <span style="color: #000088;" >$new</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #000088;" >$old</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
            delete_post_meta<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post_id</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$field</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'id'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$old</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
        <span style="color: #009900;" >&#125;</span>
    <span style="color: #009900;" >&#125;</span>
<span style="color: #009900;" >&#125;</span>
add_action<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'save_post'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'rcSaveData'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>I&#8217;m not going to go into detail about what exactly this code does as it is rather detailed, but essentially it first checks to make sure the updates were made by a person with permission to do so, then checks to make sure that we&#8217;ve made changes. If both of these checks come out okay, the data is saved to the database.</p>
<p>That&#8217;s it for the meta box.</p>
<h3>5 &#8211; User Check #1</h3>
<p>It is now time to create a series of functions that will each check for whether or not there is a restriction level set and then display the appropriate content (or lack thereof).</p>
<p>These functions are the first of two user checks we will perform.</p>
<p>Let&#8217;s first take a look at what one of these functions look like, then we will put them all together.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> rcMetaDisplaySubscriber<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$error</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >' '</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
	<span style="color: #000088;" >$custom_meta</span> <span style="color: #339933;" >=</span> get_post_custom<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$custom_meta</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'rcUserLevel'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Administrator'</span> <span style="color: #339933;" >||</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Editor'</span> <span style="color: #339933;" >||</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Author'</span><span style="color: #009900;" >&#41;</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'This content is restricted to '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$rcUserLevel</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
	<span style="color: #b1b100;" >else</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #000088;" >$error</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >&quot;&quot;</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$error</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
<span style="color: #009900;" >&#125;</span></pre></td></tr></table></div>

<p>This function first gets the user level info from the custom meta box we created above and then displays an error message if the user level is set to a value that is above the current user.</p>
<blockquote><p>Note: the user level of the current user will be determined later.</p></blockquote>
<p>We need a function like this for each user level, so all together it looks like this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> rcMetaDisplayEditor<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$error</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >' '</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
	<span style="color: #000088;" >$custom_meta</span> <span style="color: #339933;" >=</span> get_post_custom<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$custom_meta</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'rcUserLevel'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Administrator'</span><span style="color: #009900;" >&#41;</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'This content is restricted to '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$rcUserLevel</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
	<span style="color: #b1b100;" >else</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #000088;" >$error</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >&quot;&quot;</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$error</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
<span style="color: #009900;" >&#125;</span>
<span style="color: #000000; font-weight: bold;" >function</span> rcMetaDisplayAuthor<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$error</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >' '</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
&nbsp;
	<span style="color: #000088;" >$custom_meta</span> <span style="color: #339933;" >=</span> get_post_custom<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$custom_meta</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'rcUserLevel'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Administrator'</span> <span style="color: #339933;" >||</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Editor'</span><span style="color: #009900;" >&#41;</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'This content is restricted to '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$rcUserLevel</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
	<span style="color: #b1b100;" >else</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #000088;" >$error</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >&quot;&quot;</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$error</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
<span style="color: #009900;" >&#125;</span>
<span style="color: #000000; font-weight: bold;" >function</span> rcMetaDisplaySubscriber<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$error</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >' '</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
	<span style="color: #000088;" >$custom_meta</span> <span style="color: #339933;" >=</span> get_post_custom<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$custom_meta</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'rcUserLevel'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Administrator'</span> <span style="color: #339933;" >||</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Editor'</span> <span style="color: #339933;" >||</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Author'</span><span style="color: #009900;" >&#41;</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'This content is restricted to '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$rcUserLevel</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
	<span style="color: #b1b100;" >else</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #000088;" >$error</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >&quot;&quot;</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$error</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
<span style="color: #009900;" >&#125;</span>
<span style="color: #000000; font-weight: bold;" >function</span> rcMetaDisplayNone<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$error</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >' '</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
	<span style="color: #000088;" >$custom_meta</span> <span style="color: #339933;" >=</span> get_post_custom<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$custom_meta</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'rcUserLevel'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #339933;" >!</span>current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'read'</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Administrator'</span> <span style="color: #339933;" >||</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Editor'</span> <span style="color: #339933;" >||</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Author'</span> <span style="color: #339933;" >||</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'Subscriber'</span><span style="color: #009900;" >&#41;</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'This content is restricted to '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$rcUserLevel</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
	<span style="color: #b1b100;" >else</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #000088;" >$error</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >&quot;&quot;</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$error</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
<span style="color: #009900;" >&#125;</span></pre></td></tr></table></div>

<h3>6 &#8211; User Check #2</h3>
<p>The second user check is the one that is going to run inside of the WordPress loop. Even though I&#8217;ve label it <em>User Check #2</em>, it&#8217;s actually the first check that is performed. It is run from within the WordPress loop.</p>
<p>Let&#8217;s take a look at it, then we will dissect it. Copy the code below into the bottom of your plugin file.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> checkUser<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
&nbsp;
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span>current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'read'</span><span style="color: #009900;" >&#41;</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>current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'upload_files'</span><span style="color: #009900;" >&#41;</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>current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'moderate_comments'</span><span style="color: #009900;" >&#41;</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>current_user_can<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'switch_themes'</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span>
				<span style="color: #009900;" >&#123;</span>
					<span style="color: #666666; font-style: italic;" >//do nothing here for admin</span>
				<span style="color: #009900;" >&#125;</span>
				<span style="color: #b1b100;" >else</span>
				<span style="color: #009900;" >&#123;</span>
					add_filter<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'the_content'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'rcMetaDisplayEditor'</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;" >else</span>
			<span style="color: #009900;" >&#123;</span>
				add_filter<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'the_content'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'rcMetaDisplayAuthor'</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;" >else</span>
		<span style="color: #009900;" >&#123;</span>
			add_filter<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'the_content'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'rcMetaDisplaySubscriber'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		<span style="color: #009900;" >&#125;</span>
&nbsp;
	<span style="color: #009900;" >&#125;</span>
	<span style="color: #b1b100;" >else</span>
	<span style="color: #009900;" >&#123;</span>
		add_filter<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'the_content'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'rcMetaDisplayNone'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
&nbsp;
<span style="color: #009900;" >&#125;</span>
add_action<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'loop_start'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'checkUser'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>This is a linear capability check that first tests to see if the logged-in user has the minimum permission level, and if they do, it proceeds onto the second permission level check. At each stage the user either passes or fails.</p>
<p>One of the important things to notice with this user check is that all users, except for administrators, end up having a filter applied to the <em>the_content()</em> function. These filters tie directly into the functions we wrote in the above step with <em>User Check #1</em>.</p>
<p><em>User Check #2</em> allows us to determine the permission level of the current user and pass them to the correct function in <em>User Check #1</em>, which will filter the content accordingly.</p>
<p>Now that we have performed both of the user checks, we only have two more functions.</p>
<h3>7 &#8211; Add Filter to Feed Header</h3>
<p>This next function will add a small content filter to the top of all the WordPress feeds that will allow us to hide content from the feed if a post/page is restricted.</p>
<p>At the bottom of your file, put:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> rcCheckFeed<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
	add_filter<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'the_content'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'rcIsFeed'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
add_action<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'rss_head'</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >'rcCheckFeed'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<h3>8 &#8211; Check for &#8220;Hide from Feed&#8221;</h3>
<p>The last thing we need to do to finish up our plugin is to add a small function that will check whether the &#8220;Hide from Feed&#8221; option is turned on. If it is turned on, we then need to display a message like &#8220;<span style="color: red;" >This content is restricted to Editors</span>&#8220;. If it is not turned on, we do nothing but display the regular content.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >function</span> rcIsFeed<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$error</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >' '</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
	<span style="color: #000088;" >$custom_meta</span> <span style="color: #339933;" >=</span> get_post_custom<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$post</span><span style="color: #339933;" >-&gt;</span><span style="color: #004000;" >ID</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$custom_meta</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'rcUserLevel'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span>
	<span style="color: #000088;" >$rcFeedHide</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$custom_meta</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'rcFeedHide'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #cc66cc;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span>
	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span>is_feed <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #000088;" >$rcFeedHide</span> <span style="color: #339933;" >==</span> <span style="color: #0000ff;" >'on'</span><span style="color: #009900;" >&#41;</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'This content is restricted to '</span> <span style="color: #339933;" >.</span> <span style="color: #000088;" >$rcUserLevel</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'s'</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
	<span style="color: #b1b100;" >else</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #000088;" >$error</span> <span style="color: #339933;" >.=</span> <span style="color: #0000ff;" >&quot;&quot;</span><span style="color: #339933;" >;</span>
		<span style="color: #b1b100;" >return</span> <span style="color: #000088;" >$error</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
&nbsp;
<span style="color: #009900;" >&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s it! Your Restricted Content plugin is complete!</p>
<h3>9 &#8211; Going Further</h3>
<p>The first thing to do, of course, is to give your new plugin a thorough test run. Next is to extend it to have further capabilities, such as restricted categories.</p>
<p>The complete version of this plugin is available as a <a href="http://pippinspages.com/freebies/restricted-content-plugin-free/" >free download from my site</a>.</p>
<p>Enjoy!</p>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/BfQ-fyFksMo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/wordpress/how-to-write-a-restricted-content-plugin/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/wordpress/how-to-write-a-restricted-content-plugin/</feedburner:origLink></item>
		<item>
		<title>Custom Font Uploader for WordPress Themes</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/ZXjbn1F4EDg/</link>
		<comments>http://www.problogdesign.com/wordpress/custom-font-uploader-for-wordpress-themes/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 16:00:46 +0000</pubDate>
		<dc:creator>Pippin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme Options]]></category>
		<category><![CDATA[WordPress Hacks]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/?p=5506</guid>
		<description><![CDATA[<img src="http://www.problogdesign.com/wp-content/uploads/2010/06/Font-Uploader-Image.jpg" alt="" title="Font-Uploader-Image" width="560" height="145" class="alignnone size-full wp-image-5542" />

WordPress theme option panels were a tremendous stride in the world of theme development; they gave site owner's the ability to modify various aspects of their site, without ever having to touch the code. Every great theme either has or should have an extensive options panel.

In this tutorial, I'm going to demonstrate how to add a custom font uploader to your options panel. This will allow site owners to upload any number of font files and apply them to different sections of the site.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/06/Font-Uploader-Image.jpg"  alt=""  title="Font-Uploader-Image"  width="560"  height="145"  class="alignnone size-full wp-image-5542" /></p>
<p><em>Update (10th July 2010):</em> Pippin has now converted this <a href="http://pippinspages.com/wordpress/wordpress-font-uploader-plugin/" >into a premium plugin</a> which can be purchased from Code Canyon. If you&#8217;re not afraid to mess with your code a little though, read on for the DIY method!</p>
<p>WordPress theme option panels were a tremendous stride in the world of theme development; they gave site owner&#8217;s the ability to modify various aspects of their site, without ever having to touch the code. Every great theme either has or should have an extensive options panel.</p>
<p>In this tutorial, I&#8217;m going to demonstrate how to add a custom font uploader to your options panel. This will allow site owners to upload any number of font files and apply them to different sections of the site.</p>
<blockquote><p>As a designer, I cringe a little at the thought of clients possibly screwing up my carefully selected fonts with their own haphazard selection, but, in the end, it&#8217;s what the client wants.</p></blockquote>
<h3>Before Starting</h3>
<p>To begin, you first need to create your options panel. For this task, I recommend you follow <em>Rohan Mehta</em>&#8216;s tutorial over on <a href="http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/" >Net Tuts</a>. It&#8217;s the best tutorial I&#8217;ve found on this topic and will provide you with almost everything you need for this tutorial.</p>
<h3>#1 &#8211; The Essentials</h3>
<p>The first thing we need to do is create a folder called <strong>fonts</strong> in our theme directory. Your Structure should look like this:</p>
<ul>
<li>wp-content</li>
<ul>
<li>themes</li>
<ul>
<li>your_theme_folder</li>
<ul>
<li>fonts</li>
</ul>
</ul>
</ul>
</ul>
<p>For security reasons, set the permissions of this folder to <strong>774</strong>. This will allow the server to read, execute and write, while disallowing any public write / execute privileges.</p>
<p>You will also need to ensure you have a <strong>functions.php</strong> file, which, of course, you do because you&#8217;ve already followed the <a href="http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/" >Net Tuts</a> tutorial, or created an options page of your own <img src="http://www.problogdesign.com/wp-includes/images/smilies/icon_wink.gif"  alt=";-)"  class="wp-smiley" /> </p>
<h3>#2 &#8211; The Upload Script</h3>
<p>In order to actually upload files, such as custom fonts, we need to create a php upload script.</p>
<p>Save this as <strong>upload.php</strong> in your theme folder (the same place we created the <em>uploads</em> folder):</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000000; font-weight: bold;" >&lt;?php</span>
<span style="color: #666666; font-style: italic;" >//include internal wordpress functions</span>
<span style="color: #b1b100;" >require</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$_SERVER</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'DOCUMENT_ROOT'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >'/wp-blog-header.php'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #666666; font-style: italic;" >//define a maxim size for the uploaded files</span>
<span style="color: #990000;" >define</span> <span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >&quot;MAX_SIZE&quot;</span><span style="color: #339933;" >,</span><span style="color: #0000ff;" >&quot;20000000&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;" >//This function reads the extension of the file. It is used to determine if the file  is an font by checking the extension.</span>
<span style="color: #000000; font-weight: bold;" >function</span> getExtension<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$str</span><span style="color: #009900;" >&#41;</span>
<span style="color: #009900;" >&#123;</span>
   <span style="color: #000088;" >$parts</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >explode</span><span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'.'</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$str</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
   <span style="color: #b1b100;" >return</span> <span style="color: #990000;" >end</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$parts</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #009900;" >&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;" >//This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  </span>
<span style="color: #666666; font-style: italic;" >//and it will be changed to 1 if an errro occures.  </span>
<span style="color: #666666; font-style: italic;" >//If the error occures the file will not be uploaded.</span>
 <span style="color: #000088;" >$errors</span><span style="color: #339933;" >=</span><span style="color: #cc66cc;" >0</span><span style="color: #339933;" >;</span>
<span style="color: #666666; font-style: italic;" >//checks if the form has been submitted</span>
 <span style="color: #b1b100;" >if</span><span style="color: #009900;" >&#40;</span><span style="color: #990000;" >isset</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$_POST</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'Submit'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span> 
 <span style="color: #009900;" >&#123;</span>
 	<span style="color: #666666; font-style: italic;" >//reads the name of the file the user submitted for uploading</span>
 	<span style="color: #000088;" >$font</span><span style="color: #339933;" >=</span><span style="color: #000088;" >$_FILES</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'font'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'name'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span>
 	<span style="color: #666666; font-style: italic;" >//if it is not empty</span>
 	<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$font</span><span style="color: #009900;" >&#41;</span> 
 	<span style="color: #009900;" >&#123;</span>
	 	<span style="color: #666666; font-style: italic;" >//get the original name of the file from the clients machine</span>
	 		<span style="color: #000088;" >$filename</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >stripslashes</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$_FILES</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'font'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'name'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	 	<span style="color: #666666; font-style: italic;" >//get the extension of the file in a lower case format</span>
	  		<span style="color: #000088;" >$extension</span> <span style="color: #339933;" >=</span> getExtension<span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$filename</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	 		<span style="color: #000088;" >$extension</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >strtolower</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$extension</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	 	<span style="color: #666666; font-style: italic;" >//if it is not a known extension, we will suppose it is an error and will not upload the file,</span>
	 	<span style="color: #666666; font-style: italic;" >//we will only allow .ttf and .otf file extensions  </span>
		<span style="color: #666666; font-style: italic;" >//otherwise we will do more tests</span>
		<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$extension</span> <span style="color: #339933;" >!=</span> <span style="color: #0000ff;" >&quot;ttf&quot;</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$extension</span> <span style="color: #339933;" >!=</span> <span style="color: #0000ff;" >&quot;otf&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span> 
	 	<span style="color: #009900;" >&#123;</span>
			<span style="color: #666666; font-style: italic;" >//print error message</span>
	 		<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;h1&gt;Unknown extension!&lt;/h1&gt;'</span><span style="color: #339933;" >;</span>
	 		<span style="color: #000088;" >$errors</span><span style="color: #339933;" >=</span><span style="color: #cc66cc;" >1</span><span style="color: #339933;" >;</span>
	 	<span style="color: #009900;" >&#125;</span>
	 	<span style="color: #b1b100;" >else</span>
	 	<span style="color: #009900;" >&#123;</span> 		
			<span style="color: #666666; font-style: italic;" >//check the mimetypes against an allowed list</span>
			<span style="color: #000088;" >$mime</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >array</span> <span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >&quot;application/x-font-ttf&quot;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >&quot;application/vnd.oasis.opendocument.forumla-template&quot;</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >&quot;application/octet-stream&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
			<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #339933;" >!</span><span style="color: #990000;" >in_array</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$_FILES</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'font'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'type'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span><span style="color: #000088;" >$mime</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span>
			<span style="color: #009900;" >&#123;</span>
		 		<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;h1&gt;Unknown mimetype!&lt;/h1&gt;'</span><span style="color: #339933;" >;</span>
				<span style="color: #000088;" >$errors</span><span style="color: #339933;" >=</span><span style="color: #cc66cc;" >1</span><span style="color: #339933;" >;</span>
			<span style="color: #009900;" >&#125;</span>
			<span style="color: #666666; font-style: italic;" >//get the size of the file in bytes</span>
			<span style="color: #666666; font-style: italic;" >//$_FILES['image']['tmp_name'] is the temporary filename of the file</span>
			<span style="color: #666666; font-style: italic;" >//in which the uploaded file was stored on the server</span>
			<span style="color: #000088;" >$size</span><span style="color: #339933;" >=</span><span style="color: #990000;" >filesize</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$_FILES</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'font'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'tmp_name'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
			<span style="color: #666666; font-style: italic;" >//compare the size with the maxim size we defined and print error if bigger</span>
			<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$size</span> <span style="color: #339933;" >&gt;</span> MAX_SIZE<span style="color: #009900;" >&#41;</span>
			<span style="color: #009900;" >&#123;</span>
				<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;h1&gt;You have exceeded the size limit!&lt;/h1&gt;'</span><span style="color: #339933;" >;</span>
				<span style="color: #000088;" >$errors</span><span style="color: #339933;" >=</span><span style="color: #cc66cc;" >1</span><span style="color: #339933;" >;</span>
			<span style="color: #009900;" >&#125;</span>
			<span style="color: #666666; font-style: italic;" >//keep the original file name</span>
			<span style="color: #000088;" >$font_name</span><span style="color: #339933;" >=</span><span style="color: #000088;" >$filename</span><span style="color: #339933;" >;</span>
&nbsp;
			<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #339933;" >!</span><span style="color: #000088;" >$errors</span><span style="color: #009900;" >&#41;</span>
			<span style="color: #009900;" >&#123;</span>
				<span style="color: #666666; font-style: italic;" >//the new name will be containing the full path where fonts will be stored (fonts folder)</span>
				<span style="color: #000088;" >$newname</span><span style="color: #339933;" >=</span><span style="color: #0000ff;" >&quot;fonts/&quot;</span><span style="color: #339933;" >.</span><span style="color: #000088;" >$font_name</span><span style="color: #339933;" >;</span>
				<span style="color: #666666; font-style: italic;" >//we verify if the image has been uploaded, and print error instead</span>
				<span style="color: #000088;" >$copied</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >copy</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$_FILES</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'font'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'tmp_name'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$newname</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
				<span style="color: #b1b100;" >if</span> <span style="color: #009900;" >&#40;</span><span style="color: #339933;" >!</span><span style="color: #000088;" >$copied</span><span style="color: #009900;" >&#41;</span> 
				<span style="color: #009900;" >&#123;</span>
					<span style="color: #b1b100;" >echo</span> <span style="color: #0000ff;" >'&lt;h1&gt;Copy unsuccessfull!&lt;/h1&gt;'</span><span style="color: #339933;" >;</span>
					<span style="color: #000088;" >$errors</span><span style="color: #339933;" >=</span><span style="color: #cc66cc;" >1</span><span style="color: #339933;" >;</span>
				<span style="color: #009900;" >&#125;</span>
			<span style="color: #009900;" >&#125;</span>
		<span style="color: #009900;" >&#125;</span>
	<span style="color: #009900;" >&#125;</span>		
	<span style="color: #666666; font-style: italic;" >//If no errors registred, redirect back to the theme options panel</span>
	<span style="color: #b1b100;" >if</span><span style="color: #009900;" >&#40;</span><span style="color: #990000;" >isset</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$_POST</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'Submit'</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #339933;" >!</span><span style="color: #000088;" >$errors</span><span style="color: #009900;" >&#41;</span> 
	<span style="color: #009900;" >&#123;</span>
	<span style="color: #000088;" >$url</span> <span style="color: #339933;" >=</span> get_bloginfo<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'url'</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'/wp-admin/admin.php?page=functions.php'</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #990000;" >header</span> <span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >&quot;Location: <span style="color: #006699; font-weight: bold;" >$url</span>&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: #000000; font-weight: bold;" >?&gt;</span></pre></td></tr></table></div>

<p>For explanations of how this script works, read the embedded comments.</p>
<h3>#3 &#8211; Embed the Upload Script</h3>
<p>We now need to create the upload form in our options panel that will allow us to actually upload font files to the server.</p>
<p>Place this in your <strong>functions.php</strong>:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" >	&lt;h2&gt;Upload Fonts&lt;/h2&gt;
	&lt;p&gt;&lt;em&gt;Filetypes accepted: &lt;strong&gt;.ttf&lt;/strong&gt; and &lt;strong&gt;.otf&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
	&lt;p&gt;Uploaded fonts will appear in the &lt;strong&gt;FONTS&lt;/strong&gt; menu below&lt;/p&gt;
	&lt;form name=&quot;newad&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;  action=&quot;<span style="color: #000000; font-weight: bold;" >&lt;?php</span> bloginfo<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'template_directory'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span><span style="color: #000000; font-weight: bold;" >?&gt;</span>/upload.php&quot;&gt;
	 &lt;table&gt;
	 	&lt;tr&gt;
	 		&lt;td&gt;&lt;input type=&quot;file&quot; name=&quot;font&quot;&gt;&lt;/td&gt;
	 		&lt;td&gt;&lt;input name=&quot;Submit&quot; type=&quot;submit&quot; value=&quot;Upload&quot;&gt;&lt;/td&gt;
	 	&lt;/tr&gt;
	 &lt;/table&gt;	
	&lt;/form&gt;</pre></td></tr></table></div>

<p>This code provides an interface to the <strong>upload.php</strong> that we created earlier, and it looks like this:</p>
<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/06/Screen-shot-2010-06-08-at-2.08.56-PM-e1276024282962.png"  alt="upload form"  title="Upload Form"  width="559"  height="144"  class="alignnone size-full wp-image-5537" /></p>
<blockquote><p>
<strong>Important!</strong> In the Net Tuts tutorial, you created a section in functions.php that displays the theme options in a table based layout. The above code should be placed like this:
</p></blockquote>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" >&lt;div class=&quot;wrap rm_wrap&quot;&gt;
    &lt;h2&gt;<span style="color: #000000; font-weight: bold;" >&lt;?php</span> <span style="color: #b1b100;" >echo</span> <span style="color: #000088;" >$themename</span><span style="color: #339933;" >;</span> <span style="color: #000000; font-weight: bold;" >?&gt;</span> Settings&lt;/h2&gt;
    &lt;div class=&quot;rm_opts&quot;&gt;
&nbsp;
        //upload form begins here
&nbsp;
	&lt;h2&gt;Upload Fonts&lt;/h2&gt;
	&lt;p&gt;&lt;em&gt;Filetypes accepted: &lt;strong&gt;.ttf&lt;/strong&gt; and &lt;strong&gt;.otf&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
	&lt;p&gt;Uploaded fonts will appear in the &lt;strong&gt;FONTS&lt;/strong&gt; menu below&lt;/p&gt;
	&lt;form name=&quot;newad&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;  action=&quot;<span style="color: #000000; font-weight: bold;" >&lt;?php</span> bloginfo<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'template_directory'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span><span style="color: #000000; font-weight: bold;" >?&gt;</span>/upload.php&quot;&gt;
	 &lt;table&gt;
	 	&lt;tr&gt;
	 		&lt;td&gt;&lt;input type=&quot;file&quot; name=&quot;font&quot;&gt;&lt;/td&gt;
	 		&lt;td&gt;&lt;input name=&quot;Submit&quot; type=&quot;submit&quot; value=&quot;Upload&quot;&gt;&lt;/td&gt;
	 	&lt;/tr&gt;
	 &lt;/table&gt;	
	&lt;/form&gt;
&nbsp;
       //upload form ends here
&nbsp;
 &lt;form method=&quot;post&quot;&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;" >&lt;?php</span> 
                <span style="color: #b1b100;" >foreach</span> <span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$options</span> <span style="color: #b1b100;" >as</span> <span style="color: #000088;" >$value</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >:</span>
                    <span style="color: #b1b100;" >switch</span> <span style="color: #009900;" >&#40;</span> <span style="color: #000088;" >$value</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'type'</span><span style="color: #009900;" >&#93;</span> <span style="color: #009900;" >&#41;</span><span style="color: #339933;" >:</span>
                        <span style="color: #b1b100;" >case</span> <span style="color: #0000ff;" >&quot;open&quot;</span><span style="color: #339933;" >:</span>
                            <span style="color: #b1b100;" >break</span><span style="color: #339933;" >;</span>
&nbsp;
                        <span style="color: #b1b100;" >case</span> <span style="color: #0000ff;" >&quot;close&quot;</span><span style="color: #339933;" >:</span>
<span style="color: #000000; font-weight: bold;" >?&gt;</span>
. . .</pre></td></tr></table></div>

<p>If you do not place the upload form in the correct area, it will not show up in your theme options panel.</p>
<h3>#4 &#8211; List the Available Fonts</h3>
<p>We have created the ability to upload fonts and store them in a folder called <em>fonts</em>. Now we are going to create a function to list all of the available fonts inside our theme options panel.</p>
<p>Place this code in your <strong>functions.php</strong>:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000088;" >$fontsList</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #000088;" >$fontDirectoryURL</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$_SERVER</span><span style="color: #009900;" >&#91;</span><span style="color: #0000ff;" >'DOCUMENT_ROOT'</span><span style="color: #009900;" >&#93;</span> <span style="color: #339933;" >.</span> get_bloginfo<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'template_directory'</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'/fonts'</span><span style="color: #339933;" >;</span>
<span style="color: #000088;" >$removeSiteURL</span> <span style="color: #339933;" >=</span> get_bloginfo<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'url'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #000088;" >$fontDirectoryPath</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >str_replace</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$removeSiteURL</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >&quot;&quot;</span><span style="color: #339933;" >,</span> <span style="color: #000088;" >$fontDirectoryURL</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #000088;" >$fontURL</span> <span style="color: #339933;" >=</span> get_bloginfo<span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'template_directory'</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >.</span> <span style="color: #0000ff;" >'/fonts'</span><span style="color: #339933;" >;</span>
<span style="color: #000088;" >$fontDir</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >opendir</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$fontDirectoryPath</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #b1b100;" >while</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$font</span> <span style="color: #339933;" >=</span> <span style="color: #990000;" >readdir</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$fontDir</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >!==</span> <span style="color: #009900; font-weight: bold;" >false</span><span style="color: #009900;" >&#41;</span>
	<span style="color: #009900;" >&#123;</span>
		<span style="color: #b1b100;" >if</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$font</span> <span style="color: #339933;" >!=</span> <span style="color: #0000ff;" >'.'</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #000088;" >$font</span> <span style="color: #339933;" >!=</span> <span style="color: #0000ff;" >'..'</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #339933;" >!</span><span style="color: #990000;" >is_file</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$font</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #000088;" >$font</span> <span style="color: #339933;" >!=</span> <span style="color: #0000ff;" >'.htaccess'</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #000088;" >$font</span> <span style="color: #339933;" >!=</span> <span style="color: #0000ff;" >'resource.frk'</span> <span style="color: #339933;" >&amp;&amp;</span> <span style="color: #339933;" >!</span><span style="color: #990000;" >eregi</span><span style="color: #009900;" >&#40;</span><span style="color: #0000ff;" >'^Icon'</span><span style="color: #339933;" >,</span><span style="color: #000088;" >$font</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#41;</span>
			<span style="color: #009900;" >&#123;</span>
				<span style="color: #000088;" >$fontList</span><span style="color: #009900;" >&#91;</span><span style="color: #009900;" >&#93;</span> <span style="color: #339933;" >=</span> <span style="color: #000088;" >$fontURL</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >&quot;/&quot;</span><span style="color: #339933;" >.</span><span style="color: #000088;" >$font</span><span style="color: #339933;" >;</span>
			<span style="color: #009900;" >&#125;</span>
	<span style="color: #009900;" >&#125;</span>
<span style="color: #990000;" >closedir</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$fontDir</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #990000;" >array_unshift</span><span style="color: #009900;" >&#40;</span><span style="color: #000088;" >$fontList</span><span style="color: #339933;" >,</span> <span style="color: #0000ff;" >&quot;Choose a font&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>just after</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" ><span style="color: #000088;" >$themename</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >&quot;Theme-Name&quot;</span><span style="color: #339933;" >;</span>  
<span style="color: #000088;" >$shortname</span> <span style="color: #339933;" >=</span> <span style="color: #0000ff;" >&quot;sn&quot;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<blockquote><p>These two lines are created in the Net Tuts article.</p></blockquote>
<p>This is a function that works like this:</p>
<ul>
<li>create a url that will be used to access the font files in the CSS</li>
<li>open the font directory</li>
<li>read all files contained in the directory</li>
<li>exclude certain file names and directories</li>
<li>place all fonts found inside a list</li>
</ul>
<h3>#5 &#8211; Create the Font Options</h3>
<p>Anywhere among the rest of your theme options created in the Net Tuts article, place this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" ><pre class="php"  style="font-family:monospace;" >    <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span> <span style="color: #0000ff;" >&quot;name&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;Fonts&quot;</span><span style="color: #339933;" >,</span>
        <span style="color: #0000ff;" >&quot;type&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;section&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
    <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span> <span style="color: #0000ff;" >&quot;type&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;open&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
&nbsp;
	 <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span> <span style="color: #0000ff;" >&quot;name&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;Headers&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;desc&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;Choose a font&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;id&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$shortname</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >&quot;_header_font&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;type&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;select&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;options&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$fontList</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
&nbsp;
	 <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span> <span style="color: #0000ff;" >&quot;name&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;Navigation&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;desc&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;Choose a font&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;id&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$shortname</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >&quot;_nav_font&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;type&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;select&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;options&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$fontList</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
&nbsp;
	 <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span> <span style="color: #0000ff;" >&quot;name&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;Main Body&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;desc&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;Choose a font&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;id&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$shortname</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >&quot;_body_font&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;type&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;select&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;options&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$fontList</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
&nbsp;
	 <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span> <span style="color: #0000ff;" >&quot;name&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;Footer&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;desc&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;Choose a font&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;id&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$shortname</span><span style="color: #339933;" >.</span><span style="color: #0000ff;" >&quot;_footer_font&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;type&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;select&quot;</span><span style="color: #339933;" >,</span>
		<span style="color: #0000ff;" >&quot;options&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #000088;" >$fontList</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
&nbsp;
    <span style="color: #990000;" >array</span><span style="color: #009900;" >&#40;</span> <span style="color: #0000ff;" >&quot;type&quot;</span> <span style="color: #339933;" >=&gt;</span> <span style="color: #0000ff;" >&quot;close&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span></pre></td></tr></table></div>

<h3>#6 &#8211; The CSS Part One</h3>
<p>We&#8217;re going to include the fonts in our <strong>header.php</strong> file so that we can apply them to the web elements.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" ><pre class="html4strict"  style="font-family:monospace;" ><span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >style</span> <span style="color: #000066;" >type</span><span style="color: #66cc66;" >=</span><span style="color: #ff0000;" >&quot;text/css&quot;</span> <span style="color: #000066;" >media</span><span style="color: #66cc66;" >=</span><span style="color: #ff0000;" >&quot;screen&quot;</span>&gt;</span>
@font-face {
  font-family: &quot;header-font&quot;;
  src: url(&quot;<span style="color: #009900;" >&lt;?php echo get_option<span style="color: #66cc66;" >&#40;</span><span style="color: #ff0000;" >'sn_header_font'</span><span style="color: #66cc66;" >&#41;</span>; ?&gt;</span>&quot;);
}
@font-face {
  font-family: &quot;nav-font&quot;;
  src: url(&quot;<span style="color: #009900;" >&lt;?php echo get_option<span style="color: #66cc66;" >&#40;</span><span style="color: #ff0000;" >'sn_nav_font'</span><span style="color: #66cc66;" >&#41;</span>; ?&gt;</span>&quot;);
}
@font-face {
  font-family: &quot;body-font&quot;;
  src: url(&quot;<span style="color: #009900;" >&lt;?php echo get_option<span style="color: #66cc66;" >&#40;</span><span style="color: #ff0000;" >'sn_body_font'</span><span style="color: #66cc66;" >&#41;</span>; ?&gt;</span>&quot;);
}
@font-face {
  font-family: &quot;footer-font&quot;;
  src: url(&quot;<span style="color: #009900;" >&lt;?php echo get_option<span style="color: #66cc66;" >&#40;</span><span style="color: #ff0000;" >'sn_footer_font'</span><span style="color: #66cc66;" >&#41;</span>; ?&gt;</span>&quot;);
}
<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >style</span>&gt;</span></pre></td></tr></table></div>

<blockquote><p><strong>Important!</strong> Do not forget to replace <em>sn</em> with your own theme&#8217;s short name.</p></blockquote>
<h3>#6 &#8211; The CSS Part Two</h3>
<p>In your <strong>style.css</strong> file:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" ><pre class="css"  style="font-family:monospace;" >h1<span style="color: #00AA00;" >,</span>h2<span style="color: #00AA00;" >,</span>h3<span style="color: #00AA00;" >,</span>h4<span style="color: #00AA00;" >,</span>h5<span style="color: #00AA00;" >,</span>h6<span style="color: #00AA00;" >,</span>h7  <span style="color: #00AA00;" >&#123;</span>
  <span style="color: #000000; font-weight: bold;" >font-family</span><span style="color: #00AA00;" >:</span> <span style="color: #ff0000;" >&quot;header-font&quot;</span><span style="color: #00AA00;" >;</span>
<span style="color: #00AA00;" >&#125;</span>
p  <span style="color: #00AA00;" >&#123;</span>
  <span style="color: #000000; font-weight: bold;" >font-family</span><span style="color: #00AA00;" >:</span> <span style="color: #ff0000;" >&quot;body-font&quot;</span><span style="color: #00AA00;" >;</span>
<span style="color: #00AA00;" >&#125;</span>
<span style="color: #6666ff;" >.navigation</span>  <span style="color: #00AA00;" >&#123;</span>
  <span style="color: #000000; font-weight: bold;" >font-family</span><span style="color: #00AA00;" >:</span> <span style="color: #ff0000;" >&quot;nav-font&quot;</span><span style="color: #00AA00;" >;</span>
<span style="color: #00AA00;" >&#125;</span>
<span style="color: #cc00cc;" >#footer</span> p  <span style="color: #00AA00;" >&#123;</span>
  <span style="color: #000000; font-weight: bold;" >font-family</span><span style="color: #00AA00;" >:</span> <span style="color: #ff0000;" >&quot;footer-font&quot;</span><span style="color: #00AA00;" >;</span>
<span style="color: #00AA00;" >&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s it! Your final outcome should look similar to this (unless you used your own theme options page rather than following Net Tuts&#8217;):</p>
<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/06/Screen-shot-2010-06-08-at-2.12.06-PM-e1276024427690.png"  alt="font uploader"  title="Custom Font Uploader"  width="558"  height="302"  class="alignnone size-full wp-image-5538" /></p>
<h3>#7 &#8211; Going Further</h3>
<p>The system we&#8217;ve created works very well and is significantly better than any wordpress font plugin I&#8217;ve been able to find. Here are some suggestions for going a little further and making it even better:</p>
<ul>
<li>Add jQuery and or Ajax to the upload form to prevent reloading of the page and to create cleaner error / success messages</li>
<li>Create options for more specific site elements, such as <strong>p</strong> tags with a class of &#8220;antique&#8221;, rather than just generic elements as I&#8217;ve done above.</li>
<li>Allow more font file types by adding their mime types and extensions to <strong>upload.php</strong></li>
</ul>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/ZXjbn1F4EDg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/wordpress/custom-font-uploader-for-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>101</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/wordpress/custom-font-uploader-for-wordpress-themes/</feedburner:origLink></item>
		<item>
		<title>30 Pro jQuery Tips, Tricks and Strategies</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/IpcYVUa0W5Y/</link>
		<comments>http://www.problogdesign.com/coding/30-pro-jquery-tips-tricks-and-strategies/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 16:00:16 +0000</pubDate>
		<dc:creator>Nick Parsons</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/?p=5413</guid>
		<description><![CDATA[<img src="http://www.problogdesign.com/wp-content/uploads/2010/04/jquery-banner.jpg" alt="" title="jquery-banner" width="560" height="145" class="alignnone size-full wp-image-5414" />

<p>Whether you're a developer or a designer, a strong jQuery skillset is something you can't afford to be without. Today, I'm going to show you 30 handy jQuery coding tricks that will help you make your scripts more robust, elegant and professional. </p>

<h3>Getting Started</h3>
<p>These tips and tricks all have one thing in common- they are all smashingly useful. With this stuff in your back pocket, you'll be ready to go change the world, and even better, write jQuery like you know what you're doing. It's gonna be fun.</p>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/04/jquery-banner.jpg"  alt=""  title="jquery-banner"  width="560"  height="145"  class="alignnone size-full wp-image-5414" /></p>
<p>Whether you&#8217;re a developer or a designer, a strong jQuery skillset is something you can&#8217;t afford to be without. Today, I&#8217;m going to show you 30 handy jQuery coding tricks that will help you make your scripts more robust, elegant and professional. </p>
<h3>Getting Started</h3>
<p>These tips and tricks all have one thing in common- they are all smashingly useful. With this stuff in your back pocket, you&#8217;ll be ready to go change the world, and even better, write jQuery like you know what you&#8217;re doing. It&#8217;s gonna be fun.</p>
<p>We&#8217;ll start with some basic tricks, and move to some more advanced stuff like actually extending jQuery&#8217;s methods and filters. Of course, you should be familiar with the basics of jQuery first. If you haven&#8217;t used jQuery before, I highly recommend browsing the <a href="http://docs.jquery.com/" >documentation</a> and watching <a href="http://net.tutsplus.com/articles/web-roundups/jquery-for-absolute-beginners-video-series/" > jQuery for Absolute Beginners Video Series</a>. Otherwise, you&#8217;re ready to dig in!</p>
<h3>#1 &#8211; Delay with Animate()</h3>
<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/04/animate.jpg"  alt=""  title="animate"  width="560"  height="145"  class="alignnone size-full wp-image-5423" /></p>
<p>This is a very quick, easy way to cause delayed actions in jQuery without using setTimeout. The way we make it work is to add an animate function into your chain and animate the element to 100% opacity (which it&#8217;s already at), so it looks like nothing is happening.</p>
<p>For instance, let&#8217;s say that you wanted to open a dialog and then fade it away after 5 seconds. Using animate, you can do it like this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
</pre></td><td class="code" ><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;body&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >append</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;&lt;div class='dialog'&gt;&lt;/div&gt;&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #339933;" >&lt;</span>em<span style="color: #339933;" >&gt;</span>animate<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#123;</span> opacity <span style="color: #339933;" >:</span> <span style="color: #CC0000;" >1.0</span> <span style="color: #009900;" >&#125;</span><span style="color: #339933;" >,</span> <span style="color: #CC0000;" >5000</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >&lt;/</span>em<span style="color: #339933;" >&gt;</span>.<span style="color: #660066;" >fadeOut</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></pre></td></tr></table></div>

<p>Don&#8217;t you just love jQuery chaining? You&#8217;re welcome to read more about this technique from <a href="http://www.learningjquery.com/2007/01/effect-delay-trick" >Karl Swedberg</a>.</p>
<p><strong>UPDATE: </strong>jQuery 1.4 has eliminated the need for this hack with a method called <a href="http://api.jquery.com/delay/" >delay()</a>. It is just what is sounds like &#8211; a function specifically made to delay an animation effect. Way to go, jQuery!</p>
<h3>#2 &#8211; Loop through Elements Backwards</h3>
<p>One of my personal favorites is being able to loop backwards through a set of elements. We all know each() lets us easily loop through elements, but what if we need to go backwards? Here&#8217;s the trick:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" ><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: #003366; font-weight: bold;" >var</span> reversedSet <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;li&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >get</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >reverse</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;" >//Use get() to return an array of elements, and then reverse it</span>
&nbsp;
	$<span style="color: #009900;" >&#40;</span>reversedSet<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >each</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;" >//Now we can plug our reversed set right into the each function. Could it be easier?</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></td></tr></table></div>

<h3>#3 &#8211; Is There Anything in the jQuery Object?</h3>
<p>Another very elementary but regularly useful trick is checking if there are any elements in the jQuery object. For example, let&#8217;s say we need to find out if there are any elements with a class of &#8216;active&#8217; in the DOM. You can do that with a quick check of the jQuery object&#8217;s length property like this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
</pre></td><td class="code" ><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: #000066; font-weight: bold;" >if</span><span style="color: #009900;" >&#40;</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;.active&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >length</span> <span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
		<span style="color: #006600; font-style: italic;" >//Now the code here will only be executed if there is at least one active element</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></td></tr></table></div>

<p>This works because 0 evaluates false, so the expression only evaluates true if there is at least one element in the jQuery object. You can also use size() to do the same thing.</p>
<h3>#4 &#8211; Access iFrame Elements</h3>
<p>Iframes aren&#8217;t the best solution to most problems, but when you do need to use one it&#8217;s very handy to know how to access the elements inside it with Javascript. jQuery&#8217;s contents() method makes this a breeze, enabling us to load the iframe&#8217;s DOM in one line like this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
</pre></td><td class="code" ><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: #003366; font-weight: bold;" >var</span> iFrameDOM <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;iframe#someID&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >contents</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;" >//Now you can use &lt;strong&gt;find()&lt;/strong&gt; to access any element in the iframe:</span>
&nbsp;
	iFrameDOM.<span style="color: #660066;" >find</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;.message&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >slideUp</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;" >//Slides up all elements classed 'message' in the iframe</span>
<span style="color: #009900;" >&#125;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<h3>#5 &#8211; Equal Height Columns</h3>
<p>This was one of <a href="http://www.cssnewbie.com/equal-height-columns-with-jquery/" >CSS Newbie&#8217;s</a> most popular posts of 2009, and it is a good, solid trick to have in your toolbox. The function works by accepting a group of columns, measuring each one to see which is largest, and then resizing them all to match the biggest one. Here&#8217;s the code (slighly modified):</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" ><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>
	jQuery.<span style="color: #660066;" >fn</span>.<span style="color: #660066;" >equalHeight</span> <span style="color: #339933;" >=</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: #003366; font-weight: bold;" >var</span> tallest <span style="color: #339933;" >=</span> <span style="color: #CC0000;" >0</span><span style="color: #339933;" >;</span>
		<span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >each</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>
			tallest <span style="color: #339933;" >=</span> <span style="color: #009900;" >&#40;</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;" >height</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >&gt;</span> tallest<span style="color: #009900;" >&#41;</span><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;" >height</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >:</span> tallest<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: #000066; font-weight: bold;" >return</span> <span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >height</span><span style="color: #009900;" >&#40;</span>tallest<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>	
	<span style="color: #009900;" >&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//Now you can call equalHeight</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;.content-column&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >equalHeight</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></pre></td></tr></table></div>

<p>An interesting and similar concept is the awesome <a href="http://desandro.com/resources/jquery-masonry" >jQuery masonry plugin</a>, if you&#8217;re interested in checking it out.</p>
<h3>#6 &#8211; Find a Selected Phrase and Manipulate It</h3>
<p>Whether you&#8217;re looking to perform find and replace, highlight search terms, or something else, jQuery again makes it easy with html():</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" ><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: #006600; font-style: italic;" >//First define your search string, replacement and context:</span>
	<span style="color: #003366; font-weight: bold;" >var</span> phrase <span style="color: #339933;" >=</span> <span style="color: #3366CC;" >&quot;your search string&quot;</span><span style="color: #339933;" >;</span>
	<span style="color: #003366; font-weight: bold;" >var</span> replacement <span style="color: #339933;" >=</span> <span style="color: #3366CC;" >&quot;new string&quot;</span><span style="color: #339933;" >;</span>
	<span style="color: #003366; font-weight: bold;" >var</span> context <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span>body<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//</span>
	context.<span style="color: #660066;" >html</span><span style="color: #009900;" >&#40;</span>
		context.<span style="color: #660066;" >html</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >replace</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'/'</span><span style="color: #339933;" >+</span>phrase<span style="color: #339933;" >+</span><span style="color: #3366CC;" >'/gi'</span><span style="color: #339933;" >,</span> replacement<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #009900;" >&#125;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<h3>#7 &#8211; Hack Your Titles to Prevent Widows</h3>
<p>Nobody likes to see widows &#8211; but thankfully with some jQuery and a little help from &amp;nbsp; we can stop that from happening:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" ><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: #006600; font-style: italic;" >//Loop through each title</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;h3&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >each</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: #003366; font-weight: bold;" >var</span> content <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;" >text</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >split</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot; &quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		<span style="color: #003366; font-weight: bold;" >var</span> widow <span style="color: #339933;" >=</span> <span style="color: #3366CC;" >&quot;&amp;amp;nbsp;&quot;</span><span style="color: #339933;" >+</span>content.<span style="color: #660066;" >pop</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: #000066; font-weight: bold;" >this</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >html</span><span style="color: #009900;" >&#40;</span>content.<span style="color: #660066;" >join</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot; &quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >+</span>widow<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></td></tr></table></div>

<p>This technique was suggested in a comment by Bill Brown on <a href="http://css-tricks.com/snippets/jquery/add-non-breaking-space-on-title-to-prevent-widows/" >Css-Tricks</a>.</p>
<h3>#8 &#8211; Add Pseudo-Selector Support in IE</h3>
<p>Whether or not to support IE (especially 6) is a hotly debated issue, but if you are of the &#8220;let&#8217;s-make-the-best-of-this&#8221; camp, it&#8217;s nice to know that you can add pseudo-selector support with jQuery. And we aren&#8217;t just limited to :hover, although that&#8217;s the most common:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" ><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: #339933;" >&lt;</span>strong<span style="color: #339933;" >&gt;</span><span style="color: #006600; font-style: italic;" >//ADD HOVER SUPPORT:&lt;/strong&gt;</span>
	<span style="color: #003366; font-weight: bold;" >function</span> hoverOn<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
		<span style="color: #003366; font-weight: bold;" >var</span> currentClass <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;" >'class'</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >split</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >' '</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#91;</span><span style="color: #CC0000;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span> <span style="color: #006600; font-style: italic;" >//Get first class name</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;" >addClass</span><span style="color: #009900;" >&#40;</span>currentClass <span style="color: #339933;" >+</span> <span style="color: #3366CC;" >'-hover'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
	<span style="color: #003366; font-weight: bold;" >function</span> hoverOff<span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
		<span style="color: #003366; font-weight: bold;" >var</span> currentClass <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;" >'class'</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >split</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >' '</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#91;</span><span style="color: #CC0000;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span> <span style="color: #006600; font-style: italic;" >//Get first class name</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;" >removeClass</span><span style="color: #009900;" >&#40;</span>currentClass <span style="color: #339933;" >+</span> <span style="color: #3366CC;" >'-hover'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;.nav-item&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >hover</span><span style="color: #009900;" >&#40;</span>hoverOn<span style="color: #339933;" >,</span>hoverOff<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #339933;" >&lt;</span>strong<span style="color: #339933;" >&gt;</span><span style="color: #006600; font-style: italic;" >//ADD FIRST-CHILD SUPPORT:&lt;/strong&gt;</span>
	jQuery.<span style="color: #660066;" >fn</span>.<span style="color: #660066;" >firstChild</span> <span style="color: #339933;" >=</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;" >return</span> <span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >each</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: #003366; font-weight: bold;" >var</span> currentClass <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;" >'class'</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >split</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >' '</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#91;</span><span style="color: #CC0000;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span> <span style="color: #006600; font-style: italic;" >//Get first class name</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;" >children</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;:first&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >addClass</span><span style="color: #009900;" >&#40;</span>currentClass <span style="color: #339933;" >+</span> <span style="color: #3366CC;" >'-first-child'</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;" >&#40;</span><span style="color: #3366CC;" >&quot;.searchform&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >firstChild</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></pre></td></tr></table></div>

<p>The great thing about setting it up that way firstChild(), hoverOn() and hoverOff() are very reusable. Now, in the CSS we can simply add the &#8216;nav-item-hover&#8217; or &#8216;searchform-first-child&#8217; classes as additional selectors:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" ><pre class="css"  style="font-family:monospace;" ><span style="color: #6666ff;" >.nav-item</span><span style="color: #3333ff;" >:hover</span><span style="color: #00AA00;" >,</span> &lt;strong<span style="color: #00AA00;" >&gt;</span>.nav-item-hover&lt;/strong<span style="color: #00AA00;" >&gt;</span><span style="color: #00AA00;" >&#123;</span>
	<span style="color: #000000; font-weight: bold;" >background</span><span style="color: #00AA00;" >:</span><span style="color: #cc00cc;" >#FFFFFF</span><span style="color: #00AA00;" >;</span>
	<span style="color: #000000; font-weight: bold;" >border</span><span style="color: #00AA00;" >:</span> <span style="color: #993333;" >solid</span> <span style="color: #933;" >3px</span> <span style="color: #cc00cc;" >#888</span><span style="color: #00AA00;" >;</span>
<span style="color: #00AA00;" >&#125;</span>
<span style="color: #6666ff;" >.searchform</span><span style="color: #3333ff;" >:first-child</span><span style="color: #00AA00;" >,</span> &lt;strong<span style="color: #00AA00;" >&gt;</span>.searchform-first-child&lt;/strong<span style="color: #00AA00;" >&gt;</span><span style="color: #00AA00;" >&#123;</span>
	<span style="color: #000000; font-weight: bold;" >background</span><span style="color: #00AA00;" >:</span><span style="color: #cc00cc;" >#FFFFFF</span><span style="color: #00AA00;" >;</span>
	<span style="color: #000000; font-weight: bold;" >border</span><span style="color: #00AA00;" >:</span> <span style="color: #993333;" >solid</span> <span style="color: #933;" >3px</span> <span style="color: #cc00cc;" >#888</span><span style="color: #00AA00;" >;</span>
<span style="color: #00AA00;" >&#125;</span></pre></td></tr></table></div>

<p>It&#8217;s not pretty, but it is valid and it works. I&#8217;ve got to say, though, that I sure am looking forward to the day we won&#8217;t have to bother with this stuff!</p>
<h3>#9 &#8211; Manage Search Box Values</h3>
<p>A popular effect is to fill a site&#8217;s search box with a value (like &#8216;search&#8230;&#8217;) and then use jQuery to clear the default value when the field receives focus, reverting if the field is empty when blurred. That is easily accomplished with a couple lines of jQuery:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" ><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: #006600; font-style: italic;" >//set default value:</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;#searchbox&quot;</span><span style="color: #009900;" >&#41;</span>
	  .<span style="color: #660066;" >val</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'search?'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	  .<span style="color: #000066;" >focus</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;" >this</span>.<span style="color: #660066;" >val</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >''</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#125;</span><span style="color: #009900;" >&#41;</span>
	  .<span style="color: #000066;" >blur</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: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >val</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >===</span> <span style="color: #3366CC;" >''</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >?</span> <span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >val</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'search?'</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >:</span> <span style="color: #003366; font-weight: bold;" >null</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></td></tr></table></div>

<h3>#10 &#8211; Create a Disappearing &#8216;Back-to-Top&#8217; Link</h3>
<p>The disappearing back-to-top link was inspired by <a href="http://briancray.com/2009/10/06/scroll-to-top-link-jquery-css/" >Brian Cray</a>. All you have to do is add a back-to-top link at the bottom of your content like normal, and then jQuery performs the magic:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" ><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: #009966; font-style: italic;" >/* set variables locally for increased performance */</span>
	<span style="color: #003366; font-weight: bold;" >var</span> scroll_timer<span style="color: #339933;" >,</span> 
		displayed <span style="color: #339933;" >=</span> <span style="color: #003366; font-weight: bold;" >false</span><span style="color: #339933;" >,</span>
		$message <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'#message a'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
		$window <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span>window<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >,</span>
		top <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span>document.<span style="color: #660066;" >body</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >children</span><span style="color: #009900;" >&#40;</span><span style="color: #CC0000;" >0</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >position</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >top</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #009966; font-style: italic;" >/* react to scroll event on window */</span>
	$window.<span style="color: #000066;" >scroll</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>
		window.<span style="color: #660066;" >clearTimeout</span><span style="color: #009900;" >&#40;</span>scroll_timer<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		scroll_timer <span style="color: #339933;" >=</span> window.<span style="color: #660066;" >setTimeout</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;" >// use a timer for performance</span>
			<span style="color: #000066; font-weight: bold;" >if</span><span style="color: #009900;" >&#40;</span>$window.<span style="color: #660066;" >scrollTop</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >&lt;=</span> top<span style="color: #009900;" >&#41;</span> <span style="color: #006600; font-style: italic;" >// hide if at the top of the page</span>
			<span style="color: #009900;" >&#123;</span>
				displayed <span style="color: #339933;" >=</span> <span style="color: #003366; font-weight: bold;" >false</span><span style="color: #339933;" >;</span>
				$message.<span style="color: #660066;" >fadeOut</span><span style="color: #009900;" >&#40;</span><span style="color: #CC0000;" >500</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
			<span style="color: #009900;" >&#125;</span>
			<span style="color: #000066; font-weight: bold;" >else</span> <span style="color: #000066; font-weight: bold;" >if</span><span style="color: #009900;" >&#40;</span>displayed <span style="color: #339933;" >==</span> <span style="color: #003366; font-weight: bold;" >false</span><span style="color: #009900;" >&#41;</span> <span style="color: #006600; font-style: italic;" >// show if scrolling down</span>
			<span style="color: #009900;" >&#123;</span>
				displayed <span style="color: #339933;" >=</span> <span style="color: #003366; font-weight: bold;" >true</span><span style="color: #339933;" >;</span>
				$message.<span style="color: #000066;" >stop</span><span style="color: #009900;" >&#40;</span><span style="color: #003366; font-weight: bold;" >true</span><span style="color: #339933;" >,</span> <span style="color: #003366; font-weight: bold;" >true</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: #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> $message.<span style="color: #660066;" >fadeOut</span><span style="color: #009900;" >&#40;</span><span style="color: #CC0000;" >500</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;" >&#125;</span><span style="color: #339933;" >,</span> <span style="color: #CC0000;" >100</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></td></tr></table></div>

<p>Brian also added some nice-looking CSS, which you could add as a css file or define in an object literal and apply it using jQuery.css(). Feel free to go check out his <a href="http://briancray.com/2009/10/06/scroll-to-top-link-jquery-css/" >in-depth explanation</a> if you want to learn more.</p>
<h3>#11 &#8211; Easily Respond to Event Data</h3>
<p>One of my favorite things about jQuery is its convenient remapping of event data, virtually eliminating cross-browser inconsitencies and making events much easier to respond to. jQuery passes an event parameter into all bound/triggered functions, which is commonly called <em>e</em>:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" ><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: #006600; font-style: italic;" >//We can get X/Y coordinates on click events:</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;a&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: #339933;" >&lt;</span>em<span style="color: #339933;" >&gt;</span>e<span style="color: #339933;" >&lt;/</span>em<span style="color: #339933;" >&gt;</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
		<span style="color: #003366; font-weight: bold;" >var</span> clickX <span style="color: #339933;" >=</span> e.<span style="color: #660066;" >pageX</span><span style="color: #339933;" >;</span>
		<span style="color: #003366; font-weight: bold;" >var</span> clickY <span style="color: #339933;" >=</span> e.<span style="color: #660066;" >pageX</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//Or detect which key was pressed:</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;window&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >keypress</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: #339933;" >&lt;</span>em<span style="color: #339933;" >&gt;</span>e<span style="color: #339933;" >&lt;/</span>em<span style="color: #339933;" >&gt;</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
		<span style="color: #003366; font-weight: bold;" >var</span> keyPressed <span style="color: #339933;" >=</span> e.<span style="color: #660066;" >which</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></td></tr></table></div>

<p>You can check out the <a href="http://api.jquery.com/category/events/event-object/" >jQuery docs</a> on this one to see all the possibilites, or view this <a href="http://protocolsofmatrix.blogspot.com/2007/09/javascript-keycode-reference-table-for.html" >keycode reference</a> if you&#8217;d like to look up a certain key&#8217;s character code.</p>
<h3>#12 &#8211; Encode HTML Entities</h3>
<p>The first place I saw this mentioned was over at <a href="http://debuggable.com/posts/encode-html-entities-with-jquery:480f4dd6-13cc-4ce9-8071-4710cbdd56cb" >Debuggable</a>, and I have to say they really came up with something good here. The idea is to produce a jQuery result similar to PHP&#8217;s htmlentities(). Check this out:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" ><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: #003366; font-weight: bold;" >var</span> text <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;#someElement&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >text</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #003366; font-weight: bold;" >var</span> text2 <span style="color: #339933;" >=</span> <span style="color: #3366CC;" >&quot;Some &lt;code&gt; &amp; such to encode&quot;</span><span style="color: #339933;" >;</span>
	<span style="color: #006600; font-style: italic;" >//you can define a string or get the text of an element or field</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;" >var</span> html <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span>text<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >html</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #003366; font-weight: bold;" >var</span> html2 <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span>text2<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >html</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;" >//Done - html and html2 now hold the encoded values!</span>
<span style="color: #009900;" >&#125;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<h3>#13 &#8211; Friendly Text Resizing</h3>
<p>Originally mentioned at <a href="http://www.shopdev.co.uk/blog/text-resizing-with-jquery/" >ShopDev</a>, this is an excellent way to include some user-centricity in your code (allowing them to control the font-size):</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" ><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: #006600; font-style: italic;" >// Reset Font Size</span>
  <span style="color: #003366; font-weight: bold;" >var</span> originalFontSize <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'html'</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >css</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'font-size'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
    $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;.resetFont&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;" >'html'</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >css</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'font-size'</span><span style="color: #339933;" >,</span> originalFontSize<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: #006600; font-style: italic;" >// Increase Font Size</span>
  $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;.increaseFont&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: #003366; font-weight: bold;" >var</span> currentFontSize <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'html'</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >css</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'font-size'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
    <span style="color: #003366; font-weight: bold;" >var</span> currentFontSizeNum <span style="color: #339933;" >=</span> parseFloat<span style="color: #009900;" >&#40;</span>currentFontSize<span style="color: #339933;" >,</span> <span style="color: #CC0000;" >10</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
    <span style="color: #003366; font-weight: bold;" >var</span> newFontSize <span style="color: #339933;" >=</span> currentFontSizeNum<span style="color: #339933;" >*</span><span style="color: #CC0000;" >1.2</span><span style="color: #339933;" >;</span>
    $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'html'</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >css</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'font-size'</span><span style="color: #339933;" >,</span> newFontSize<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
    <span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #003366; font-weight: bold;" >false</span><span style="color: #339933;" >;</span>
  <span style="color: #009900;" >&#125;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
  <span style="color: #006600; font-style: italic;" >// Decrease Font Size</span>
  $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;.decreaseFont&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: #003366; font-weight: bold;" >var</span> currentFontSize <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'html'</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >css</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'font-size'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
    <span style="color: #003366; font-weight: bold;" >var</span> currentFontSizeNum <span style="color: #339933;" >=</span> parseFloat<span style="color: #009900;" >&#40;</span>currentFontSize<span style="color: #339933;" >,</span> <span style="color: #CC0000;" >10</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
    <span style="color: #003366; font-weight: bold;" >var</span> newFontSize <span style="color: #339933;" >=</span> currentFontSizeNum<span style="color: #339933;" >*</span><span style="color: #CC0000;" >0.8</span><span style="color: #339933;" >;</span>
    $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'html'</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >css</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'font-size'</span><span style="color: #339933;" >,</span> newFontSize<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
    <span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #003366; font-weight: bold;" >false</span><span style="color: #339933;" >;</span>
  <span style="color: #009900;" >&#125;</span><span style="color: #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></td></tr></table></div>

<p>As I said, this is nice trick to know and adds some of that dynamic friendliness that people enjoy so much.</p>
<h3>#14 &#8211; Open External Links in a New Window</h3>
<p>This external links hack has been mentioned before at <a href="http://www.catswhocode.com/blog/8-awesome-jquery-tips-and-tricks" >Cats Who Code</a>, and although imperfect it&#8217;s a good way to open external links in new windows without causing validation errors in XHTML 1.0 Strict.</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
</pre></td><td class="code" ><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;" >'a[rel$='</span>external<span style="color: #3366CC;" >']'</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;" >this</span>.<span style="color: #660066;" >target</span> <span style="color: #339933;" >=</span> <span style="color: #3366CC;" >&quot;_blank&quot;</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></td></tr></table></div>

<p>This works by grabbing all links with an external rel and adding a blank target. Same result, it&#8217;s just not hardcoded into the site.</p>
<h3>#15 &#8211; Gracefully Degrading AJAX Navigation</h3>
<p>AJAX navigation is great &#8211; but not for users and bots who can&#8217;t use it. The good news is, it&#8217;s possible to offer direct links to your content while still presenting AJAX functionality (to users who have that capability) by catching links before they go anywhere, returning false on them and loading the AJAX content instead. It could look like this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
</pre></td><td class="code" ><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;a&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >bind</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;click&quot;</span><span style="color: #339933;" >,</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;" >//Put your AJAX request code here</span>
		<span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #003366; font-weight: bold;" >false</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span><span style="color: #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></td></tr></table></div>

<p>Of course, this is very basic, but it&#8217;s an essential facet to any AJAX navigation. You can also check out SpeckyBoy&#8217;s post on <a href="http://speckyboy.com/2008/10/19/35-easy-to-use-free-ajax-navigation-solutions/" >Easy-to-Use Free Ajax Navigation Solutions.</a></p>
<h3>#16 &#8211; Create an Array of GET variables</h3>
<p>Although this is not specifically a jQuery trick, it&#8217;s useful enough to be included here. Using GET variables in Javascript code doesn&#8217;t happen everyday, but when it does you&#8217;ll want to know a quick and efficient way to read them. All we have to do is get document.location.search and do some parsing on it:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" ><pre class="javascript"  style="font-family:monospace;" >&nbsp;
<span style="color: #003366; font-weight: bold;" >var</span> searchArray <span style="color: #339933;" >=</span> document.<span style="color: #660066;" >location</span>.<span style="color: #660066;" >search</span>.<span style="color: #660066;" >substring</span><span style="color: #009900;" >&#40;</span><span style="color: #CC0000;" >1</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >split</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;&amp;&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
<span style="color: #006600; font-style: italic;" >//Take off the '?' and split into separate queries</span>
&nbsp;
<span style="color: #006600; font-style: italic;" >//Now we'll loop through searchArray and create an associative array (object literal) called GET</span>
<span style="color: #003366; font-weight: bold;" >var</span> GET <span style="color: #339933;" >=</span> <span style="color: #009900;" >&#91;</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span> 
<span style="color: #000066; font-weight: bold;" >for</span> <span style="color: #009900;" >&#40;</span>searchTerm <span style="color: #000066; font-weight: bold;" >in</span> searchArray<span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
	searchTerm.<span style="color: #660066;" >split</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;=&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span> <span style="color: #006600; font-style: italic;" >//Divide the searchTerm into property and value</span>
	GET<span style="color: #009900;" >&#91;</span>searchTerm<span style="color: #009900;" >&#91;</span><span style="color: #CC0000;" >0</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#93;</span> <span style="color: #339933;" >=</span> searchTerm<span style="color: #009900;" >&#91;</span><span style="color: #CC0000;" >1</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >;</span> <span style="color: #006600; font-style: italic;" >//Add property and value to the GET array</span>
<span style="color: #009900;" >&#125;</span></pre></td></tr></table></div>

<h3>#17 &#8211; Partial Page Refresh Using load()</h3>
<p>This excellent technique found at the <a href="http://blog.mediasoft.be/partial-page-refresh-with-ajax-and-jquery/" >Mediasoft Blog</a> is way cool and very handy for creating a regularly updating dashboard/widget/etc. It works by using jQuery.load() to perform a AJAX request:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
</pre></td><td class="code" ><pre class="javascript"  style="font-family:monospace;" >$<span style="color: #009900;" >&#40;</span>document<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >ready</span><span style="color: #009900;" >&#40;</span><span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	setInterval<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;#content&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >load</span><span style="color: #009900;" >&#40;</span>location.<span style="color: #660066;" >href</span><span style="color: #339933;" >+</span><span style="color: #3366CC;" >&quot; #content&gt;*&quot;</span><span style="color: #339933;" >,</span><span style="color: #3366CC;" >&quot;&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
	<span style="color: #009900;" >&#125;</span><span style="color: #339933;" >,</span> <span style="color: #CC0000;" >5000</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></td></tr></table></div>

<p>Voila! It works &#8211; no iframes, meta refreshes or other such nonsense.</p>
<h3>#18 &#8211; Skin with jQuery UI</h3>
<p>If you&#8217;re going to write any jQuery plugins (I hope you <a href="http://net.tutsplus.com/videos/screencasts/you-still-cant-create-a-jquery-plugin/" >have already!</a>), you should know that a great way to add flexibility and elegance is to incorporate jQueryUI theming classes into any widgets/visible elements your plugin produces. The great thing about doing this is that it cuts or eliminates the css you have to provide with the plugin, and it adds a lot of customizability, too (which is one of the key factors in a successful plugin).</p>
<p>And the actual implementation is as simple as learning how the classes work and attaching them to plugin elements. I can see this would be especially great with plugins like form beautifiers and photo sliders, making it easy to keep a consistent look throughout a website or app. You can check out the <a href="http://jqueryui.com/docs/Theming/API" >Theming Reference here.</a></p>
<h3>#19 &#8211; Include Other Scripts</h3>
<p><a href="http://net.tutsplus.com/tutorials/javascript-ajax/jquery-style-switcher/" >Stylesheet switchers</a> are nothing new, but adding other scripts with jQuery is something that is often overlooked. The advantage is twofold:</p>
<ol>
<li>It makes it easy to have lazy script loading.</li>
<li>It also allows us to add scripts at runtime, which could be useful in a whole host of situations.</li>
</ol>
<p>It&#8217;s as easy as using append() to add a new script to the head of the document:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" ><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;head&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >append</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;&lt;script type='text/javascript' src='somescript.js'&gt;&lt;/script&gt;&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//Or, loading only when the slow stuff is ready:</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;img,form&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >load</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;head&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >append</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;&lt;script type='text/javascript' src='somescript.js'&gt;&lt;/script&gt;&quot;</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></td></tr></table></div>

<h3>#20 &#8211; Use Body Classes for Easy Styling</h3>
<p>Do you want to save on code and keep your styling in the css file where it should be? Body classes (another great ideas suggested by <a href="http://www.learningjquery.com/2008/10/1-way-to-avoid-the-flash-of-unstyled-content" >Karl Swedberg</a>) allow you to do that. In short, you can use jQuery to add a &#8216;JS&#8217; class to the body element, which will enable you to set styles in your css that will only be applied if Javascript is enabled. For example: </p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
</pre></td><td class="code" ><pre class="javascript"  style="font-family:monospace;" >$<span style="color: #009900;" >&#40;</span>document<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >ready</span><span style="color: #009900;" >&#40;</span><span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;body&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >addClass</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;JS&quot;</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></td></tr></table></div>

<p>For Javascript users the body now has a JS class, so in our CSS we can add styles like this:</p>
<pre name="code"  class="css" >
ul.navigation{
	display:block;
}
.JS ul.navigation{
	display:none;
}
</pre>
<p>This gives us a great way to change styles based on whether or not Javascript is supported/enabled, and we can still keep the styling in the CSS file. Another interesting related use of this technique is to add browser classes to the body, enabling easy browser-specific styling. You can read more about that <a href="http://www.nathanrice.net/blog/browser-detection-and-the-body_class-function/" >here</a>.</p>
<h3>#21 &#8211; Optimize Your Performance</h3>
<p>Experienced coders don&#8217;t make clients wait &#8211; they write code that runs fast! There are several ways you can make your code run faster like:</p>
<ul>
<li>Reference id&#8217;s rather than classes (id selection is native and therefore quicker)</li>
<li>Use for instead of each()</li>
<li>Limit DOM manipulation by adding elements in one big chunk rather than one at a time</li>
<li>Take advantage of <a href="http://www.learningjquery.com/2009/09/working-with-events-part-3-more-event-delegation-with-jquery" >event delegation</a></li>
<li>Link to Google&#8217;s jQuery copy rather than hosting your own &#8211; it&#8217;s faster and always up to date</li>
</ul>
<p>Basically, it all boils down to not making jQuery do any more work than it has to (and using native abilites whenever possible). Giulio Bai wrote an <a href="http://net.tutsplus.com/tutorials/javascript-ajax/10-ways-to-instantly-increase-your-jquery-performance/" >excellent post on jQuery perfomance</a>, if you&#8217;d like to dig in deeper.</p>
<h3>#22 &#8211; Adapt Your Scripts to Work Cross-Browser &#8211; The <em>Right</em> Way</h3>
<p>Thankfully, jQuery&#8217;s cross-browser compatibility really cuts down the need for browser hacks. Sometimes, though, it is good to be able to get information about the client, and we can do that cleanly and unobtrusively with jQuery.support:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
</pre></td><td class="code" ><pre class="javascript"  style="font-family:monospace;" ><span style="color: #006600; font-style: italic;" >//Does this client follow the W3C box model?</span>
<span style="color: #003366; font-weight: bold;" >var</span> boxModel <span style="color: #339933;" >=</span> $.<span style="color: #660066;" >support</span>.<span style="color: #660066;" >boxModel</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #006600; font-style: italic;" >//Does this client support 'opacity'?</span>
<span style="color: #003366; font-weight: bold;" >var</span> opacity <span style="color: #339933;" >=</span> $.<span style="color: #660066;" >support</span>.<span style="color: #660066;" >opacity</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<p>It&#8217;s definitely better practice to use feature-detection rather than browser sniffing, and this is a very efficient way to do it. Read more about jQuery.support&#8217;s properties <a href="http://api.jquery.com/jQuery.support/" >here.</a></p>
<h3>#23 &#8211; Configure jQuery to be Compatible with Other Libraries</h3>
<p>We all find ourselves in situations where multiple libraries are needed, and because jQuery isn&#8217;t the only library that uses the $ alias, compatiblity issues sometimes pop up. Thankfully, this is easy to fix using jQuery&#8217;s noConflict(). You can even define a custom alias to replace the $:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
</pre></td><td class="code" ><pre class="javascript"  style="font-family:monospace;" ><span style="color: #003366; font-weight: bold;" >var</span> $j <span style="color: #339933;" >=</span> jQuery.<span style="color: #660066;" >noConflict</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
<span style="color: #006600; font-style: italic;" >//Now you can use '$j' just like '$'</span>
$j<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;div&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></pre></td></tr></table></div>

<p>An alternate technique is to wrap jQuery calls in an anonymous function and pass jQuery in as a parameter. Then you can use whatever alias you want, including the &#8216;$&#8217;. This is especially useful for plugin authoring:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
</pre></td><td class="code" ><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>document<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >ready</span><span style="color: #009900;" >&#40;</span><span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
		<span style="color: #006600; font-style: italic;" >//You can use normal jQuery syntax here</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: #009900;" >&#40;</span>jQuery<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<h3>#24 &#8211; Efficiently Store Element-Specific Information with data()</h3>
<p>data() is probably one of the lesser used jQuery methods, although it certainly shouldn&#8217;t be. It allows us to attach/retrieve as much data as we want to DOM elements without misusing attributes, and is especially useful for more complex scripts. For example, Stefan Petre&#8217;s <a href="http://eyecon.ro/colorpicker/" >Colorpicker plugin</a> uses data a lot because it&#8217;s tracking lots of fields and colors, converting rgb to hex, etc. Here&#8217;s are some examples of how data() works:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" ><pre class="javascript"  style="font-family:monospace;" >$<span style="color: #009900;" >&#40;</span>document<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >ready</span><span style="color: #009900;" >&#40;</span><span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	<span style="color: #006600; font-style: italic;" >//Set status to 'unsaved'</span>
    $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;button:first&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >data</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;status&quot;</span><span style="color: #339933;" >,</span> <span style="color: #3366CC;" >&quot;unsaved&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//Retrieve status</span>
	<span style="color: #003366; font-weight: bold;" >var</span> buttonStatus <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;button:first&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >data</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;status&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//Change status, this time defining an object literal</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;button:first&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >data</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;status&quot;</span><span style="color: #339933;" >,</span> <span style="color: #009900;" >&#123;</span>saved <span style="color: #339933;" >:</span> <span style="color: #003366; font-weight: bold;" >true</span><span style="color: #339933;" >,</span> index <span style="color: #339933;" >:</span> <span style="color: #CC0000;" >1</span><span style="color: #009900;" >&#125;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//Retrieve status of index property</span>
	<span style="color: #003366; font-weight: bold;" >var</span> buttonStatusIndex <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;button:first&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >data</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;status&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >index</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//Remove status data</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;button:first&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >removeData</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;status&quot;</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></td></tr></table></div>

<p>I&#8217;m sure you can imagine the huge extent of possibilities this presents. Again, it&#8217;s worth reading the <a href="http://api.jquery.com/data/" >documentation</a> if you haven&#8217;t used data() before.</p>
<h3>#25 &#8211; Extend/Modify Existing jQuery Functions</h3>
<p>Nobody says you can&#8217;t use the existing jQuery platform as a springboard for new ideas &#8211; and many have done just that using <a href="http://api.jquery.com/jQuery.extend/" >extend()</a>, another wonderful jQuery method. The popular <a href="http://plugins.jquery.com/project/Easing" >Easing plugin</a>, for example, adds some animation variety by extending the easing object, an already existing object that is passed to animate() and others:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" ><pre class="javascript"  style="font-family:monospace;" >jQuery.<span style="color: #660066;" >extend</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#123;</span>
	easing<span style="color: #339933;" >:</span> <span style="color: #009900;" >&#123;</span>
		easein<span style="color: #339933;" >:</span> <span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span>x<span style="color: #339933;" >,</span> t<span style="color: #339933;" >,</span> b<span style="color: #339933;" >,</span> c<span style="color: #339933;" >,</span> d<span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
			<span style="color: #000066; font-weight: bold;" >return</span> c<span style="color: #339933;" >*</span><span style="color: #009900;" >&#40;</span>t<span style="color: #339933;" >/=</span>d<span style="color: #009900;" >&#41;</span><span style="color: #339933;" >*</span>t <span style="color: #339933;" >+</span> b<span style="color: #339933;" >;</span> <span style="color: #006600; font-style: italic;" >// in</span>
		<span style="color: #009900;" >&#125;</span><span style="color: #339933;" >,</span>
		easeinout<span style="color: #339933;" >:</span> <span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span>x<span style="color: #339933;" >,</span> t<span style="color: #339933;" >,</span> b<span style="color: #339933;" >,</span> c<span style="color: #339933;" >,</span> d<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>t <span style="color: #339933;" >&lt;</span> d<span style="color: #339933;" >/</span><span style="color: #CC0000;" >2</span><span style="color: #009900;" >&#41;</span> <span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #CC0000;" >2</span><span style="color: #339933;" >*</span>c<span style="color: #339933;" >*</span>t<span style="color: #339933;" >*</span>t<span style="color: #339933;" >/</span><span style="color: #009900;" >&#40;</span>d<span style="color: #339933;" >*</span>d<span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >+</span> b<span style="color: #339933;" >;</span>
			<span style="color: #003366; font-weight: bold;" >var</span> ts <span style="color: #339933;" >=</span> t <span style="color: #339933;" >-</span> d<span style="color: #339933;" >/</span><span style="color: #CC0000;" >2</span><span style="color: #339933;" >;</span>
			<span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #339933;" >-</span><span style="color: #CC0000;" >2</span><span style="color: #339933;" >*</span>c<span style="color: #339933;" >*</span>ts<span style="color: #339933;" >*</span>ts<span style="color: #339933;" >/</span><span style="color: #009900;" >&#40;</span>d<span style="color: #339933;" >*</span>d<span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >+</span> <span style="color: #CC0000;" >2</span><span style="color: #339933;" >*</span>c<span style="color: #339933;" >*</span>ts<span style="color: #339933;" >/</span>d <span style="color: #339933;" >+</span> c<span style="color: #339933;" >/</span><span style="color: #CC0000;" >2</span> <span style="color: #339933;" >+</span> b<span style="color: #339933;" >;</span>		
		<span style="color: #009900;" >&#125;</span><span style="color: #339933;" >,</span>
		easeout<span style="color: #339933;" >:</span> <span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span>x<span style="color: #339933;" >,</span> t<span style="color: #339933;" >,</span> b<span style="color: #339933;" >,</span> c<span style="color: #339933;" >,</span> d<span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
			<span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #339933;" >-</span>c<span style="color: #339933;" >*</span>t<span style="color: #339933;" >*</span>t<span style="color: #339933;" >/</span><span style="color: #009900;" >&#40;</span>d<span style="color: #339933;" >*</span>d<span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >+</span> <span style="color: #CC0000;" >2</span><span style="color: #339933;" >*</span>c<span style="color: #339933;" >*</span>t<span style="color: #339933;" >/</span>d <span style="color: #339933;" >+</span> b<span style="color: #339933;" >;</span>
		<span style="color: #009900;" >&#125;</span>...</pre></td></tr></table></div>

<p>By extending and improving jQuery&#8217;s default functionality, you can open up a whole new world of cool possibilities.</p>
<h3>#26 &#8211; Reverse Engineer before() and after()</h3>
<p>I always appreciated how jQuery provided append()/prepend() <em>and</em> appendTo()/prependTo(), enabling us to easily perform an append in either direction. I&#8217;ve wished, though, that a similar ability was provided with before() and after(). To change that, we can easily add two functions called putBefore() and putAfter() that will fulfill that purpose. Here&#8217;s how:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" ><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>
	jQuery.<span style="color: #660066;" >fn</span>.<span style="color: #660066;" >putBefore</span> <span style="color: #339933;" >=</span> <span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span>dest<span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
		<span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >each</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>dest<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >before</span><span style="color: #009900;" >&#40;</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: #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>
	jQuery.<span style="color: #660066;" >fn</span>.<span style="color: #660066;" >putAfter</span> <span style="color: #339933;" >=</span> <span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span>dest<span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
		<span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >each</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>dest<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >after</span><span style="color: #009900;" >&#40;</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: #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;" >&#125;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span></pre></td></tr></table></div>

<h3>#27 &#8211; Add an isChildOf() Test</h3>
<p>I&#8217;m sure we all have found ourselves in this situation &#8211; needing to know if an element is a descendant of another element. The good news is, with one line of code we can extend jQuery to allow this:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" ><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>
	jQuery.<span style="color: #660066;" >fn</span>.<span style="color: #660066;" >isChildOf</span> <span style="color: #339933;" >=</span> <span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span>b<span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span><span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #009900;" >&#40;</span><span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >parents</span><span style="color: #009900;" >&#40;</span>b<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >length</span> <span style="color: #339933;" >&gt;</span> <span style="color: #CC0000;" >0</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span><span style="color: #009900;" >&#125;</span><span style="color: #339933;" >;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//Now we can evaluate like this:</span>
	<span style="color: #000066; font-weight: bold;" >if</span> <span style="color: #009900;" >&#40;</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;li&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >isChildOf</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;ul&quot;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#41;</span><span style="color: #009900;" >&#123;</span>
		<span style="color: #006600; font-style: italic;" >//Obviously, the li is a child of the ul so this code is executed</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></td></tr></table></div>

<p>Thanks to <a href="http://blog.pengoworks.com/index.cfm/2008/9/24/Using-jQuery-to-determine-if-an-element-is-a-child-of-another-element" >Dan Switzer II</a> for this contribution!</p>
<h3>#28 &#8211; Add Custom Selectors</h3>
<p>This is another one that has been talked about a lot in the development community, so you may have this already figured out. If not, get ready because this will open some whole new windows for jQuery efficiency. The short story is, jQuery allows us to extend its expression object, which means we can add whatever custom selectors we want. For example, say we wanted to add a selector version of the isChildOf() method we wrote earlier:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" ><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>
	jQuery.<span style="color: #660066;" >extend</span><span style="color: #009900;" >&#40;</span>jQuery.<span style="color: #660066;" >expr</span><span style="color: #009900;" >&#91;</span><span style="color: #3366CC;" >':'</span><span style="color: #009900;" >&#93;</span><span style="color: #339933;" >,</span> <span style="color: #009900;" >&#123;</span>   
		<span style="color: #3366CC;" >'child-of'</span> <span style="color: #339933;" >:</span> <span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span>a<span style="color: #339933;" >,</span>b<span style="color: #339933;" >,</span>c<span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
			<span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #009900;" >&#40;</span>jQuery<span style="color: #009900;" >&#40;</span>a<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >parents</span><span style="color: #009900;" >&#40;</span>c<span style="color: #009900;" >&#91;</span><span style="color: #CC0000;" >3</span><span style="color: #009900;" >&#93;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >length</span> <span style="color: #339933;" >&gt;</span> <span style="color: #CC0000;" >0</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>
&nbsp;
	<span style="color: #006600; font-style: italic;" >//'child-of' is now a valid selector:</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;li:child-of(ul.test)&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >css</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;background&quot;</span><span style="color: #339933;" >,</span><span style="color: #3366CC;" >&quot;#000&quot;</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></td></tr></table></div>

<p><a href="http://debuggable.com/posts/getting-serious-with-jquery-adding-custom-css-selectors:480f4dd6-e834-4cf6-a5cc-478ccbdd56cb" >Debuggable</a> has a great post on this one as well, if you&#8217;d like to read more about how the parameters work, etc.</p>
<h3>#29 &#8211; Smooth Scrolling Without Plugin</h3>
<p>Karl Swedberg posted this one a while back on the <a href="http://www.learningjquery.com/2007/08/animated-scrolling-for-same-page-links" >Learning jQuery</a> site, and it is definitely worth a look. Of course, there are a couple of plugins to accomplish this (and they have more features), but I think the real value in this is the excercise of doing it yourself. Plus, look at how tiny it is:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" ><pre class="javascript"  style="font-family:monospace;" >$<span style="color: #009900;" >&#40;</span>document<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >ready</span><span style="color: #009900;" >&#40;</span><span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
  $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'a[href*=#]'</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>location.<span style="color: #660066;" >pathname</span>.<span style="color: #660066;" >replace</span><span style="color: #009900;" >&#40;</span><span style="color: #009966; font-style: italic;" >/^\//</span><span style="color: #339933;" >,</span><span style="color: #3366CC;" >''</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >==</span> <span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >pathname</span>.<span style="color: #660066;" >replace</span><span style="color: #009900;" >&#40;</span><span style="color: #009966; font-style: italic;" >/^\//</span><span style="color: #339933;" >,</span><span style="color: #3366CC;" >''</span><span style="color: #009900;" >&#41;</span> 
      <span style="color: #339933;" >&amp;&amp;</span> location.<span style="color: #660066;" >hostname</span> <span style="color: #339933;" >==</span> <span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >hostname</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
       <span style="color: #003366; font-weight: bold;" >var</span> $target <span style="color: #339933;" >=</span> $<span style="color: #009900;" >&#40;</span><span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >hash</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
       $target <span style="color: #339933;" >=</span> $target.<span style="color: #660066;" >length</span> <span style="color: #339933;" >&amp;&amp;</span> $target <span style="color: #339933;" >||</span> $<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >'[name='</span> <span style="color: #339933;" >+</span> <span style="color: #000066; font-weight: bold;" >this</span>.<span style="color: #660066;" >hash</span>.<span style="color: #660066;" >slice</span><span style="color: #009900;" >&#40;</span><span style="color: #CC0000;" >1</span><span style="color: #009900;" >&#41;</span> <span style="color: #339933;" >+</span><span style="color: #3366CC;" >']'</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
       <span style="color: #000066; font-weight: bold;" >if</span> <span style="color: #009900;" >&#40;</span>$target.<span style="color: #660066;" >length</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
           $target.<span style="color: #660066;" >ScrollTo</span><span style="color: #009900;" >&#40;</span><span style="color: #CC0000;" >400</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
           <span style="color: #000066; font-weight: bold;" >return</span> <span style="color: #003366; font-weight: bold;" >false</span><span style="color: #339933;" >;</span>
       <span style="color: #009900;" >&#125;</span>
    <span style="color: #009900;" >&#125;</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></td></tr></table></div>

<h3>#30 &#8211; Add Tabs without a Plugin</h3>
<p>jQuery tabs are often covered but also often used, and like the scrolling trick above it&#8217;s important to know how to do these without a plugin. The first thing to do is write our markup, which should be perfectly presentable in the absence of Javascript:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" ><pre class="html4strict"  style="font-family:monospace;" ><span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >div</span> <span style="color: #000066;" >class</span><span style="color: #66cc66;" >=</span><span style="color: #ff0000;" >&quot;widget&quot;</span>&gt;</span>
	<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >h3</span>&gt;</span>Popular<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >h3</span>&gt;</span>
	<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >ul</span>&gt;</span>
		<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>Item #1<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>
		<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>Item #2<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>
		<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>Item #3<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>
	<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >ul</span>&gt;</span>
<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >div</span>&gt;</span>
<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >div</span> <span style="color: #000066;" >class</span><span style="color: #66cc66;" >=</span><span style="color: #ff0000;" >&quot;widget&quot;</span>&gt;</span>
	<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >h3</span>&gt;</span>Recent<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >h3</span>&gt;</span>
	<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >ul</span>&gt;</span>
		<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>Item #1<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>
		<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>Item #2<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>
		<span style="color: #009900;" >&lt;<span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>Item #3<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >li</span>&gt;</span>
	<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >ul</span>&gt;</span>
<span style="color: #009900;" >&lt;<span style="color: #66cc66;" >/</span><span style="color: #000000; font-weight: bold;" >div</span>&gt;</span></pre></td></tr></table></div>

<p>With a bit of styling, this would look just fine, so we know our jQuery is going to degrade gracefully. Now we can write the code:</p>

<div class="wp_syntax" ><table><tr><td class="line_numbers" ><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" ><pre class="javascript"  style="font-family:monospace;" >$<span style="color: #009900;" >&#40;</span>document<span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >ready</span><span style="color: #009900;" >&#40;</span><span style="color: #003366; font-weight: bold;" >function</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span> <span style="color: #009900;" >&#123;</span>
	$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;div.widget&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: #660066;" >filter</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;:first&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >before</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;&lt;ul class='tabs'&gt;&lt;/ul&gt;&lt;div class='tab-content'&gt;&lt;/div&gt;&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >add</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;div.widget&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >each</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: #000066; font-weight: bold;" >this</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >find</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;ul&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >appendTo</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;.tab-content&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;ul.tabs&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >append</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;&lt;li&gt;&quot;</span> <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;" >find</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;:header:first&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >text</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >+</span> <span style="color: #3366CC;" >&quot;&lt;/li&gt;&quot;</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;" >&#40;</span><span style="color: #3366CC;" >&quot;ul.tabs li&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: #000066; font-weight: bold;" >this</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >addClass</span><span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;active&quot;</span><span style="color: #009900;" >&#41;</span><span style="color: #339933;" >;</span>
		$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;.tab-content ul&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >slideUp</span><span style="color: #009900;" >&#40;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >eq</span><span style="color: #009900;" >&#40;</span>$<span style="color: #009900;" >&#40;</span><span style="color: #3366CC;" >&quot;ul.tabs li&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >index</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: #009900;" >&#41;</span>.<span style="color: #660066;" >slideDown</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;" >&#40;</span><span style="color: #3366CC;" >&quot;ul.tabs li:first&quot;</span><span style="color: #009900;" >&#41;</span>.<span style="color: #660066;" >click</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></pre></td></tr></table></div>

<p>Of course, that&#8217;s just one way to do it. If you&#8217;d like to see some other approaches, see Extra Tuts&#8217; <a href="http://www.extratuts.com/amazing-jquery-tabs-tutorials" >jQuery Tabs Tutorials</a> collection.</p>
<h3>Wrapping Up</h3>
<p>Thanks for reading, I hope you&#8217;ve enjoyed it! In case you&#8217;re all fired up on jQuery now, here are some links to more great tips n&#8217; tricks collections:</p>
<ul>
<li><a href="http://www.jquery.wisdomplug.com/jquery-tips-and-tricks/20-best-jquery-tips-and-tricks-collection/" >20 Best jQuery Tips and Tricks Collection</a> (a master roundup)
<li><a href="http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx" >Improve Your jQuery &#8211; 25 Excellent Tips</a></li>
<li><a href="http://www.geekology.co.za/blog/2009/10/12-tips-improve-your-jquery-code/" >12 Tips to Improve Your jQuery Code</a></li>
<li><a href="http://www.catswhocode.com/blog/8-awesome-jquery-tips-and-tricks" >8 Awesome jQuery Tips &#038; Tricks</a></li>
</ul>
<p>As you can see, there are infinite opportunities for amazing innovation with jQuery. So keep experimenting, keep trying things, keep thinking, &#8220;What if?&#8221; You could be the next jQuery supergeek!</p>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/IpcYVUa0W5Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/coding/30-pro-jquery-tips-tricks-and-strategies/feed/</wfw:commentRss>
		<slash:comments>67</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/coding/30-pro-jquery-tips-tricks-and-strategies/</feedburner:origLink></item>
		<item>
		<title>I Just Dont Care About the GPL/Licenses</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/o6_1HsQkluE/</link>
		<comments>http://www.problogdesign.com/wordpress/i-just-dont-care-about-the-gpllicenses/#comments</comments>
		<pubDate>Fri, 21 May 2010 00:56:35 +0000</pubDate>
		<dc:creator>Michael Martin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[GPL]]></category>
		<category><![CDATA[Licenses]]></category>
		<category><![CDATA[PliablePress]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/?p=5495</guid>
		<description><![CDATA[<img src="http://www.problogdesign.com/wp-content/uploads/2010/05/pliablepress-gpl.jpg" alt="PliablePress and the GPL" title="PliablePress and the GPL" width="560" height="145" class="alignnone size-full wp-image-5499" />

There has been another GPL storm going on in the WordPress world in the past few days. Yep, again.

I don't normally make a comment on them, but given that I'm directly involved with it now through <a href="http://www.pliablepress.com/">PliablePress themes</a> (All of our themes have to come with some sort of license, right?), it seems time to finally step in.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/05/pliablepress-gpl.jpg"  alt="PliablePress and the GPL"  title="PliablePress and the GPL"  width="560"  height="145"  class="alignnone size-full wp-image-5499" /></p>
<p><em><strong>Update 15 July 2010:</strong> PliablePress is now 100% GPL compliant! <a href="http://www.pliablepress.com/2010/07/pliablepress-now-100-gpl/" >Read more here</a>. I still stand by most of what I said here about product quality being more important than a license, but I was wrong to underestimate how important the GPL is to a lot of people. Thanks to everyone for the enlightened discussions we had here, the change is because of you all!</em></p>
<p>There has been another GPL storm going on in the WordPress world in the past few days. Yep, again.</p>
<p>I don&#8217;t normally make a comment on them, but given that I&#8217;m directly involved with it now through <a href="http://www.pliablepress.com/" >PliablePress themes</a> (All of our themes have to come with some sort of license, right?), it seems time to finally step in.</p>
<h2>An Ultra-Fast Backstory</h2>
<p>WordPress is licensed under the GPL, which means <strong>anyone can copy, edit, sell or redistribute it</strong>. Obviously if you&#8217;re going to sell themes (or plugins) though, that license poses a bit of an issue because it literally means people can buy it once and sell it for less (or for nothing!) elsewhere.</p>
<p>Matt Mullenweg (Founder of WordPress) <strong>wants all themes to be GPL</strong>. He&#8217;s said he will never take this to court, but he is using his resources as founder to do his best to promote GPL themes (e.g. GPL themes are promoted on the WordPress.org site, whilst non-GPL themes aren&#8217;t allowed to be mentioned anywhere on it).</p>
<p>The latest fuss is because Jane Wells has <a href="http://wordcamphowto.wordpress.com/2010/05/19/fyi-im-taking-over-as-central-liaison/" >taken over as the central point</a> for WordCamp info and now says that <strong>anyone who sells non-GPL products is forbidden from speaking at a WordCamp</strong>, or advertising.</p>
<h2>What Exactly Is the PliablePress License?</h2>
<p>I&#8217;ll answer this quickly before I get into the main point; PliablePress doesn&#8217;t have a real license. It has 5 lines that I wrote about 3 hours before we went live. It basically says that you can do anything you want with your theme, so long as you <strong>don&#8217;t sell it on or give it to someone else</strong>.</p>
<p>So you can <strong>edit, customize and expand on it as much as you want</strong>, for every single site you have. But if your friend wants to use it, they have to buy their own copy (Though you can totally get them to buy it through your <a href="http://www.pliablepress.com/members/aff_signup.php" >affiliate link</a> and earn yourself 33% back!)</p>
<p>Now here is the interesting part; I don&#8217;t actually mention the license anywhere on the site until you&#8217;re in the checkout. And in the 11 days since we launched, I&#8217;ve been asked <strong>hundreds of questions from different people all about PliablePress</strong> and our themes.</p>
<p>Want to know <strong>how many asked about the license?</strong> <em>None</em> (Okay, one person, but he&#8217;s a special case and you&#8217;ll be hearing much more about him on the <a href="http://www.pliablepress.com/blog/" >PliablePress blog</a> soon!)</p>
<p>That&#8217;s the important thing to realize here, <strong>just how few people really care</strong>. At PliablePress, we&#8217;re going to do whatever it takes to make your site the absolute best it can be. And that&#8217;s all our customers seem to want so far. One license or another doesn&#8217;t help them with that.</p>
<h2>So Why Not Go GPL?</h2>
<p>Because it&#8217;s a very big decision!</p>
<p>Once you GPL a product, you can&#8217;t undo that. That&#8217;s kind of the point. If we go GPL, it&#8217;s permanent. That kind of decision needs some serious thought, and you know what? <strong>I have better things to do</strong>.</p>
<p><a href="http://www.pliablepress.com/themes/chameleon/" >Chameleon</a> packs in an absolute boat-load of functionality, and we had 5 full themes on launch. I don&#8217;t think we have a single customer who would have preferred that I&#8217;d spent the time looking into this GPL issue and left out some of our features. And that&#8217;s what it&#8217;s all about, <strong>doing what is best for you, our customers.</strong></p>
<p>Since we&#8217;ve launched, I&#8217;ve replied to questions about any kind of issue our users have met. I&#8217;ve built <a href="http://www.pliablepress.com/2010/05/use-custom-icons-in-your-social-widget/" >new features</a> into the themes because people wanted them already, and I&#8217;ve written entire chunks of code for individual people just so they can adapt their theme the way they want it.</p>
<p>In short, I&#8217;m making sure you can take one of our themes and make it <strong>exactly the way you like</strong>. And we&#8217;re yet to have one dissatisfied customer, so I think we&#8217;re doing a pretty good job!</p>
<p>If you can show me<strong> how the &#8220;license&#8221; I mentioned above stops me from doing that</strong>, well, maybe I&#8217;ll go GPL after all then! It&#8217;s like I said; whatever it takes to make your site rock.</p>
<h2>Will You Ever Go GPL?</h2>
<p>Maybe. But to be honest, it&#8217;s not likely to happen in the near future.</p>
<p>There are too many things happening (Like the number of &#8220;bundle&#8221; theme sites opening lately), and sometimes the whole thing just <strong>feels like a farce</strong>. It&#8217;s a great marketing trick for some companies (That much is clear when you realize that only their WordPress products are GPL. If they believe in the GPL, why not their other products too?), and it provides a lot of discussion for others (Including me now, it seems!)</p>
<p>The best route seems to be to sit on the sideline and work away at making our products the best they can be. When the storms all die out and the dust settles, <strong>we&#8217;ll check back in and see how things stand then</strong>.</p>
<h2>What About the WordCamps?</h2>
<p>I&#8217;ve spent <strong>the past 3 years</strong> writing hundreds of tips and tricks for getting the most out of WordPress here. I&#8217;ve brought dozens of clients to WordPress through our <a href="http://www.problogdesign.com/services/" >services</a>, I&#8217;ve written around 1500 comments on this site talking to you all about it, and I don&#8217;t even want to think about just how many WordPress questions I&#8217;ve answered in emails.</p>
<p>And I&#8217;ve <strong>loved every minute of it</strong>. It feels great helping someone out and hearing them say they appreciated it. And with near 11,000 daily subscribers here, your guess is as good as mine at just how many people have made use of these tips!</p>
<p>And with the exception of the design services (obviously!), I&#8217;ve done <strong>all of that for free.</strong></p>
<p>But now that I&#8217;m taking what I&#8217;ve learnt further and building awesome themes that let you do half the things I talk about here just by clicking a button, <strong>I&#8217;m not welcome in Jane Wells&#8217; community?</strong></p>
<p>Oh well.</p>
<p>It&#8217;s <strong>not going to change how I do things</strong>. You&#8217;re still going to get loads of great tutorials on improving your site, I&#8217;m still going to be talking to every single one of you in the comments, on <a href="http://twitter.com/problogdesign" >Twitter</a>, or anywhere else. And PliablePress is still going to create themes that <a href="http://www.pliablepress.com/themes/" >make your site rock</a>.</p>
<p>Don&#8217;t get me wrong though, I&#8217;m not totally aloof to it all. <strong>I do think it&#8217;s a shame</strong> I&#8217;m no longer wanted at a WordCamp, and it&#8217;s disheartening to see this weight-throwing by the WordCamp trademark owners (especially when WordCamp began as a way for WordPress fans to simply get together and learn from each other. Now count how many times Jane has used the word official in <a href="http://wordcamphowto.wordpress.com/2010/05/19/fyi-im-taking-over-as-central-liaison/" >that short post</a>. It was a lot simpler than that before).</p>
<p>But that&#8217;s just the way of it. If you don&#8217;t want to be part of that, then don&#8217;t be. Just get on with what you&#8217;re doing and make sure you&#8217;re taking care of <strong>the people who really matter, your readers and your customers</strong>. That&#8217;s what I do.</p>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/o6_1HsQkluE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/wordpress/i-just-dont-care-about-the-gpllicenses/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/wordpress/i-just-dont-care-about-the-gpllicenses/</feedburner:origLink></item>
		<item>
		<title>Get Your WordPress Themes from PliablePress!</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/QrRCgp8sCgk/</link>
		<comments>http://www.problogdesign.com/wordpress/get-your-wordpress-themes-from-pliablepress/#comments</comments>
		<pubDate>Tue, 11 May 2010 16:09:38 +0000</pubDate>
		<dc:creator>Michael Martin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[PliablePress]]></category>
		<category><![CDATA[Premium Themes]]></category>
		<category><![CDATA[Pro Blog Design]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/wordpress/get-your-wordpress-themes-from-pliablepress/</guid>
		<description><![CDATA[<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="intro" border="0" alt="intro" src="http://www.problogdesign.com/wp-content/uploads/2010/05/intro.jpg" width="560" height="145" /> </p>  <p>Anyone following me on Twitter will already know this by now, but our big project, <a href="http://www.pliablepress.com/" target="_blank">PliablePress</a>, <strong>went live around 24 hours ago</strong>!</p>  <p>And it’s been great! <strong>It’s been crazy</strong> and I’ve been chasing things around everywhere and I meant to have this post published, well, 24 hours ago, but all of that aside, it’s been great.</p>  <p>We’ve had loads of <strong>great reactions to the designs</strong>, and even our first happy customers!</p>  <p>In this post I want to show you what we’ve done so far, share some videos of <a href="http://www.problogdesign.com/wordpress/my-ideal-wordpress-framework/" target="_blank">the framework</a> in action, and <strong>offer you a discount</strong> if you want to become a customer!</p> ]]></description>
			<content:encoded><![CDATA[<p><img border="0"  style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px"  title="intro"  alt="intro"  src="http://www.problogdesign.com/wp-content/uploads/2010/05/intro.jpg"  width="560"  height="145" /> </p>
<p>Anyone following me on Twitter will already know this by now, but our big project, <a href="http://www.pliablepress.com/"  target="_blank" >PliablePress</a>, <strong>went live around 24 hours ago</strong>!</p>
<p>And it’s been great! <strong>It’s been crazy</strong> and I’ve been chasing things around everywhere and I meant to have this post published, well, 24 hours ago, but all of that aside, it’s been great.</p>
<p>We’ve had loads of <strong>great reactions to the designs</strong>, and even our first happy customers!</p>
<p>In this post I want to show you what we’ve done so far, share some videos of <a href="http://www.problogdesign.com/wordpress/my-ideal-wordpress-framework/"  target="_blank" >the framework</a> in action, and <strong>offer you a discount</strong> if you want to become a customer!</p>
<h2>Want to See Our Designs?</h2>
<p>Click on any image to see its full page (including a live demo link!) on PliablePress.</p>
<p><a href="http://www.pliablepress.com/themes/creative-soul/"  target="_blank" ><img align="left"  border="0"  style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px"  title="square-cs"  alt="square-cs"  src="http://www.problogdesign.com/wp-content/uploads/2010/05/squarecs.jpg"  width="280"  height="280" /></a> <a href="http://www.pliablepress.com/themes/oracle/"  target="_blank" ><img border="0"  style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px"  title="square-oracle"  alt="square-oracle"  src="http://www.problogdesign.com/wp-content/uploads/2010/05/squareoracle.jpg"  width="280"  height="280" /></a></p>
<p><a href="http://www.pliablepress.com/themes/creative-soul-minimal/"  target="_blank" ><img align="left"  border="0"  style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px"  title="square-cs-minimal"  alt="square-cs-minimal"  src="http://www.problogdesign.com/wp-content/uploads/2010/05/squarecsminimal.jpg"  width="280"  height="280" /></a><a href="http://www.pliablepress.com/themes/backdrop/"  target="_blank" ><img border="0"  style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px"  title="square-backdrop"  alt="square-backdrop"  src="http://www.problogdesign.com/wp-content/uploads/2010/05/squarebackdrop.jpg"  width="280"  height="280" /></a></p>
<p><a href="http://www.pliablepress.com/themes/chameleon/"  target="_blank" ><img border="0"  style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px"  title="long-chameleon"  alt="long-chameleon"  src="http://www.problogdesign.com/wp-content/uploads/2010/05/longchameleon.jpg"  width="560"  height="145" /></a>&#160;&#160;&#160; </p>
<p>With any purchase, <strong>you will get Chameleon for free</strong> (Chameleon is our framework, which all of the themes need to run on. They’re all child themes of Chameleon)</p>
<h2>The Framework in Action</h2>
<p>I’ve used Screenr to record some videos of the framework in use. It limits you to 5 minutes a video though so I’ve split it up into 3 videos. <a href="http://www.pliablepress.com/2010/05/see-the-chameleon-options-panel-in-action/"  target="_blank" >Check out this post</a> to see all 3 in a row!</p>
<p>(Or if you want to be really quick; the first gives you a general idea of the framework, and the <strong>second shows you some of the cooler features of it</strong>!)</p>
<p>Click here for the <a href="http://www.pliablepress.com/2010/05/see-the-chameleon-options-panel-in-action/"  target="_blank" >Chameleon demo videos</a>.</p>
<h2>Get a $30 Discount &amp; A Free Theme!</h2>
<p>Originally I promised everyone a $25 discount, but I upped that at the last minute to $30, and there’s a special offer surrounding our next theme.</p>
<p>The $30 coupon expires in about 30 hours now, so you’ll need to act quick!</p>
<p>When you sign up, just enter this coupon: <strong>LAUNCHDAY</strong></p>
<p>If the $30 expires though, don’t worry, I’m still offering $25 off until the end of next week so you can still make a big saving!</p>
<p>In that case, just enter this coupon on the signup page: <strong>LAUNCH2010</strong></p>
<h4>How Can You Get Our Next Theme For Free?</h4>
<p>Our next theme is called MyBiz, and it’s a very modern <strong>website and blog theme</strong> (You’ll see what I mean when you see the homepage below!).</p>
<p>Anyone who buys <strong>any theme from us in the next 2 weeks will get a free copy of MyBiz</strong> (And all its color variations!) when we launch it!</p>
<p>And now, here’s a new preview of MyBiz that I haven’t shared anywhere yet!</p>
<p><img border="0"  style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px"  title="mybiz-pbd"  alt="mybiz-pbd"  src="http://www.problogdesign.com/wp-content/uploads/2010/05/mybizpbd.jpg"  width="560"  height="400" /> </p>
<p>Quite different to the blue preview you may have seen in the newsletter yesterday, isn’t it? And there are <strong>more variations on their way</strong>, so stay tuned!</p>
<p>That’s us live though! It’s been a rollercoaster ride getting here, but I’m delighted to finally be able to share this all with you, and I’d love to hear what you think of it all! (or better yet, <a href="http://www.pliablepress.com/themes/"  target="_blank" >buy a theme</a> and <strong>try it out on your site!</strong> And make sure you share the link with me if you do!)</p>
<p>And last of all, if you&#8217;d like to take part in our affiliate program, just <a href="http://www.pliablepress.com/members/aff_signup.php" >sign up for an account here</a>! We&#8217;re offering a huge 33% for any sales referred through one of your links, so it could be well worth your while!</p>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/QrRCgp8sCgk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/wordpress/get-your-wordpress-themes-from-pliablepress/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/wordpress/get-your-wordpress-themes-from-pliablepress/</feedburner:origLink></item>
		<item>
		<title>3 Years On, Time To Show You Who I am?</title>
		<link>http://feedproxy.google.com/~r/ProBlogDesign/~3/diOJ6YCKlAU/</link>
		<comments>http://www.problogdesign.com/other/3-years-on-time-to-show-you-who-i-am/#comments</comments>
		<pubDate>Mon, 03 May 2010 16:00:00 +0000</pubDate>
		<dc:creator>Michael Martin</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[PliablePress]]></category>
		<category><![CDATA[Pro Blog Design]]></category>

		<guid isPermaLink="false">http://www.problogdesign.com/other/3-years-on-time-to-show-you-who-i-am/</guid>
		<description><![CDATA[<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="3yearson" border="0" alt="3yearson" src="http://www.problogdesign.com/wp-content/uploads/2010/05/3yearson.png" width="560" height="145" /></p>  <p><em>(This is more of a personal post than normal. If that’s not your thing, sorry, but at least I warned you!)</em></p>  <p>My name’s Michael Martin, and I’m <strong>the person behind Pro Blog Design</strong>. If you’ve ever emailed in, tweeted, or left a Facebook message (or most likely, even if you’ve just left a comment here!) then you’ve talked to me before.</p>]]></description>
			<content:encoded><![CDATA[<p><img border="0"  style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px"  title="3yearson"  alt="3yearson"  src="http://www.problogdesign.com/wp-content/uploads/2010/05/3yearson.png"  width="560"  height="145" /></p>
<p><em>(This is more of a personal post than normal. If that’s not your thing, sorry, but at least I warned you!)</em></p>
<p>My name’s Michael Martin, and I’m <strong>the person behind Pro Blog Design</strong>. If you’ve ever emailed in, tweeted, or left a Facebook message (or most likely, even if you’ve just left a comment here!) then you’ve talked to me before.</p>
<p>And if you’ve been here at all before, you’ve definitely read <strong>articles I’ve written</strong> (and naturally if you’ve <a title="Custom design services we offer."  href="http://www.problogdesign.com/services/"  target="_blank" >worked with us</a>, you’ve probably had more emails from me than you actually wanted!)</p>
<p>But you’ve never seen a photo of me.</p>
<p>In one week from today, I launch the <a title="PliablePress of course!"  href="http://www.pliablepress.com/"  target="_blank" >biggest project of my life</a>, and it just <strong>doesn’t seem fair</strong> to ask you to purchase something from me without knowing who I am.</p>
<p>So you’ll have to forgive this being a bit of dull post. It’s for those of you who really want to <strong>get involved with PliablePress</strong> and take part in shaping what it becomes. The first step towards that is introductions.</p>
<h2>So Who Am I?</h2>
<p><img src="http://www.problogdesign.com/wp-content/uploads/2010/05/pbd11.jpg"  alt="Michael Martin"  title="Michael Martin"  width="280"  height="280"  class="alignright size-full wp-image-5433" /> Well, that’s me over there on the right!</p>
<p>The reason you’ve never seen a photo before is that I was fairly young when I started Pro Blog Design. </p>
<p>I’m 20 now, and have the reputation of 3 years writing and designing at Pro Blog Design to back me up.</p>
<p>When I started out though, I was 17 and wondered if I’d have trouble with people taking me seriously or not. I never lied about my age, I just avoided bringing it up.</p>
<p>The awesome thing about the internet though is that <strong>the very best people</strong> (ie. the ones you actually want to work with, and the ones you want to be your customers) really couldn’t care less what age you are (Or where you’re from, or anything else for that matter). They just want you to<strong> know your stuff</strong>.</p>
<p>It <strong>took me a while to realize</strong> that, and I probably could (and should!) have put photos online before now. Maybe a few people would have been put off, but not the important ones (A few especially perceptive clients even worked it out because of the times I sent most of my emails at, and none were bothered).</p>
<p>Kind of nice to have done that now, I think I was the only person in the world to have <a title="Pro Blog Design&#39;s Facebook page."  href="http://www.facebook.com/problogdesign"  target="_blank" >Facebook</a> and not have a single photo on it!</p>
<h2>What All Do You Do?</h2>
<p>I’m a full time student at Queen’s University, Belfast, studying Computer Science (It’s good most of the time, but if you were having concerns about Flash now, have you <strong>ever even heard of Adobe Director?</strong> Yawn…).</p>
<p>Pro Blog Design is where the real fun happens though. When I started out, and for quite a while afterwards, this was all <strong>a one man show</strong>. I wrote all the posts, handled all the communications, and did all the design and code work.</p>
<p>Now I still write a lot of posts and do all the communications, but instead of writing every post, I often hire other writers and then work as an editor. And instead of doing all of the design work by myself, I now oversee it and guide the project (Though I do most of the coding myself, and all of the coding in <a title="Our WordPress framework."  href="http://www.problogdesign.com/wordpress/my-ideal-wordpress-framework/"  target="_blank" >Chameleon</a> of course).</p>
<p>Why change to a team effort? Well for one thing, I needed to. Productivity is one thing, but there’s a point where even the most colorful of to-do lists and focus tricks aren’t going to take you any further…</p>
<p>The best reason though is that I get to work with people who are better than me. If you hire us to design your website now, you’re going to get <strong>a much better site than if you’d hired just me</strong> 3 years ago.</p>
<p>Why? Because I work with <strong>designers who are better than me</strong>. I’ve done enough design work myself to know a fantastic designer when I see them, and that’s why at Pro Blog Design, you only get the best.</p>
<p>Sorry if that seems like a copout as a freelancer, but anyone who thinks they’re the very best at everything they do just isn’t being honest with themselves. Everyone has strengths, and the only way to build something awesome is to <strong>find people who rock at the areas you’re just “good” in</strong>.</p>
<p>For me, that meant graphic design in particular (Ever notice how I don’t write Photoshop tutorials? I can make your site as user-friendly and functional as you like, but for really eye-grabbing graphics, I knew I needed to pair up with an awesome designer)</p>
<h2>The Exciting Part</h2>
<p>So now you know who I am and what I do, I have some <strong>news to share</strong> with you. Up until now, I’ve always had something full time to work on aside from Pro Blog Design (i.e. university), but that’s about to change.</p>
<p>The next year in my course is supposed to be spent working in industry for a year. For me, it means that come June <strong>I’ll be working full time on the web</strong> for (at least!) the next 16 months. And I can’t wait!</p>
<p>So if you thought everything up until now was good, just wait until I’m <strong>able to go at it full throttle! </strong>And naturally, <a href="http://www.pliablepress.com/"  target="_blank" >PliablePress</a> is going to be a massive part of that.</p>
<p>If you made it this far down the post, thanks for taking the time to read it all. Now that you know me, I’d love to know you.</p>
<p>With PliablePress, we really are going to <strong>involve you in everything</strong>. We’ve done enough work on the web to have a good idea of what you will like, but it’s not possible to know that better than you do.</p>
<p>If you want to get involved and help shape PliablePress, I’d be delighted. A big part of that will be in discussions on the user forum when we launch, and on the blog, but the first step is just <a href="http://www.pliablepress.com/"  target="_blank" >joining the newsletter</a>. We’re going to have some <strong>big questions on it soon</strong> and I’d love to hear your opinions.</p>
<p></p>
<style type="text/css" >
#mc-embedded-subscribe:hover {background:#cbef58;cursor:pointer;}
</style>
<div id="mc_embed_signup" >
<form action="http://pliablepress.us1.list-manage.com/subscribe/post?u=40d70d8ea2598b70f4907c661&amp;id=9095e6d9e1"  method="post"  id="mc-embedded-subscribe-form"  name="mc-embedded-subscribe-form"  class="validate"  target="_blank"  style="background:#e3f0f2;padding:20px 20px 20px 50px;" >
<div class="mc-field-group" >
<input type="text"  value="Enter your email..."  onfocus="if(this.value=='Enter your email...')this.value=''"  onblur="if(this.value=='')this.value='Enter your email...'"  name="EMAIL"  class="required email"  id="mce-EMAIL"  style="float:left;display:block;width:300px;background:#fff;border:1px solid #ededed;padding:2px 10px;height:18px;line-height:18px;" />
</div>
<div id="mce-responses" >
<div class="response"  id="mce-error-response"  style="display:none" ></div>
<div class="response"  id="mce-success-response"  style="display:none" ></div>
</p></div>
<div>
<input type="submit"  value="Send to Me!"  name="subscribe"  id="mc-embedded-subscribe"  class="btn"  style="float:left;padding:3px 10px;background:#acd42a;color:#113140;text-align:center;font-weight:bold;" /></div>
<div class="clear" ></div>
</form>
</div>
<p></p>
<p>And if you’ve been following along in the background in all this or we haven’t spoken much before, <strong>please do introduce yourself in the comments</strong> (let me know who you are and how I can help you!). I’m not joking in the slightest about wanting to get to know you.</p>
<p>It’s just 7 days to the launch. I hope this post took you a little further along the road to <strong>trusting me to make your site rock</strong>!</p>
<img src="http://feeds.feedburner.com/~r/ProBlogDesign/~4/diOJ6YCKlAU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.problogdesign.com/other/3-years-on-time-to-show-you-who-i-am/feed/</wfw:commentRss>
		<slash:comments>157</slash:comments>
		<feedburner:origLink>http://www.problogdesign.com/other/3-years-on-time-to-show-you-who-i-am/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 9.882 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-09-03 20:03:42 -->
