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

<channel>
	<title>bavotasan.com &#187; Tutorials</title>
	<atom:link href="http://bavotasan.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://bavotasan.com</link>
	<description>by c.bavota</description>
	<lastBuildDate>Tue, 07 Feb 2012 15:42:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using :target to Create a Lightbox Effect with CSS3</title>
		<link>http://bavotasan.com/2012/using-target-to-create-a-lightbox-effect-with-css3/</link>
		<comments>http://bavotasan.com/2012/using-target-to-create-a-lightbox-effect-with-css3/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 15:42:10 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[effect]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[lightbox]]></category>
		<category><![CDATA[pseudo class]]></category>
		<category><![CDATA[transition]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3794</guid>
		<description><![CDATA[If you&#8217;ve messed around with CSS3 you have probably seen some of the new pseudo classes pop up here and there. An interesting one that I just started to use is :target. A full explanation of what it does can be found on the W3 site but for the purposes of this tutorial, we will [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve messed around with CSS3 you have probably seen some of the new pseudo classes pop up here and there. An interesting one that I just started to use is <code>:target</code>. A full explanation of what it does can be found on the <a href="http://www.w3.org/TR/selectors/#target-pseudo">W3 site</a> but for the purposes of this tutorial, we will be using it to create a Lightbox effect. I actually developed this for <a href="http://presswork.me">PressWork</a> and so I decided to call it Pressbox.</p>
<p>First we need to create a thumbnail and surround it with an anchor tag.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#image1&quot;</span><span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://yoursite.com/images/image1.jpg&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>The <code>href</code> parameter is very important since it will be what links our thumbnail to our larger image. We will use the same name as the ID in our larger image like so:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;image1&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pressbox&quot;</span><span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://yoursite.com/images/image1-big.jpg&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>The larger image needs a class that we can reference. I used <code>pressbox</code> but you can use whatever you want as long as you modify the CSS accordingly. Here is the CSS that will get everything working properly:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.pressbox</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">9999</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0.7</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.pressbox</span> img	<span style="color: #00AA00;">&#123;</span>
		opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</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;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
		-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">15px</span> <span style="color: #cc00cc;">#444</span><span style="color: #00AA00;">;</span>
		-moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">15px</span> <span style="color: #cc00cc;">#444</span><span style="color: #00AA00;">;</span>	
		box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">15px</span> <span style="color: #cc00cc;">#444</span><span style="color: #00AA00;">;</span>	
		-moz-transition<span style="color: #00AA00;">:</span> opacity .25s ease-in-out<span style="color: #00AA00;">;</span>
		-webkit-transition<span style="color: #00AA00;">:</span> opacity .25s ease-in-out<span style="color: #00AA00;">;</span>
		transition<span style="color: #00AA00;">:</span> opacity .25s ease-in-out<span style="color: #00AA00;">;</span>		
		<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.pressbox</span><span style="color: #3333ff;">:target </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.pressbox</span><span style="color: #3333ff;">:target </span>img <span style="color: #00AA00;">&#123;</span>
		opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>We&#8217;ve added an opacity transition so that our Pressbox will fade in once we click on the thumbnail. This will all work because of the <code>:target</code> pseudo class that will display the the element that uses the same ID that is referenced by the <code>href</code> parameter in the thumbnail&#8217;s anchor tag.</p>
<p>You can test it out below. </p>
<p><a href="#image1"><img src="http://bavotasan.com/wp-content/uploads/2012/02/pressbox-demo.jpg" alt="" title="pressbox-demo" width="200" height="150" class="alignnone size-full wp-image-3796" /></a><br />
<a href="#" id="image1" class="pressbox"><img src="http://bavotasan.com/wp-content/uploads/2012/02/pressbox-demo-big.jpg" alt="" title="pressbox-demo-big" width="800" height="536" class="alignnone size-full wp-image-3795" /></a></p>
<p>Remember that this will only work in the following browsers: </p>
<ul>
<li>Firefox 1.0+</li>
<li>Safari 3.1+</li>
<li>Opera 9.5+</li>
<li>Chrome 2+</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2012/using-target-to-create-a-lightbox-effect-with-css3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Increase Max Upload File Size in WordPress</title>
		<link>http://bavotasan.com/2012/increase-max-upload-file-size-in-wordpress/</link>
		<comments>http://bavotasan.com/2012/increase-max-upload-file-size-in-wordpress/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 21:12:51 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[post_max_size]]></category>
		<category><![CDATA[uploader]]></category>
		<category><![CDATA[upload_max_filesize]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3764</guid>
		<description><![CDATA[Sometimes, you need to upload a large file to your site, and the default 8mb limit in WordPress isn&#8217;t enough. I attempted to change my limit directly on my server, then in the .htaccess file and then in wp-config.php but neither change worked for me. Then I came across this little snippet by Word Impressed [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you need to upload a large file to your site, and the default 8mb limit in WordPress isn&#8217;t enough. I attempted to change my limit directly on my server, then in the .htaccess file and then in wp-config.php but neither change worked for me. Then I came across this little snippet by <a href="http://www.wordimpressed.com/coding/how-to-increase-wordpress-file-upload-size-correctly/">Word Impressed</a> which actually worked and allowed me to increase my max upload file size limit.</p>
<p>All you need to do is create a <code>php.ini</code> file and upload it into your <code>/wp-admin</code> folder. Then add the following:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">memory_limit <span style="color: #339933;">=</span> 32M
upload_max_filesize <span style="color: #339933;">=</span> 32M
post_max_size <span style="color: #339933;">=</span> 32M
file_uploads <span style="color: #339933;">=</span> On</pre></div></td></tr></table></div>

<p>You can change <code>32m</code> to whatever max file size you want.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2012/increase-max-upload-file-size-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Shortcode to Encode Email in WordPress Posts</title>
		<link>http://bavotasan.com/2012/shortcode-to-encode-email-in-wordpress-posts/</link>
		<comments>http://bavotasan.com/2012/shortcode-to-encode-email-in-wordpress-posts/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 22:18:05 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[antispambot]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3762</guid>
		<description><![CDATA[A while back I wrote a short tutorial entitled &#8220;A Clever and Safe Way to Display your Email Address&#8221; which explained how you could use CSS to safely display your email on a web page. That way still works well but if you&#8217;re using WordPress, you can take advantage of a function called antispambot() to [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I wrote a short tutorial entitled <a href="http://bit.ly/cuRBa2">&#8220;A Clever and Safe Way to Display your Email Address&#8221;</a> which explained how you could use CSS to safely display your email on a web page. That way still works well but if you&#8217;re using WordPress, you can take advantage of a function called <code>antispambot()</code> to display emails addresses anywhere on your site. </p>
<p>If you code a page template directly, you can add the function like so:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">antispambot<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;youremail@yoursite.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>I needed a away to take advantage of the <code>antispambot()</code> function within my post and page content, so I decided to create a shortcode that would make it super easy to reuse.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// EMAIL ENCODE SHORTCODE</span>
<span style="color: #000000; font-weight: bold;">function</span> email_encode_function<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: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span>antispambot<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mailto:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span>antispambot<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: #0000ff;">'&lt;/a&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;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'email_encode_function'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>Once you add the above code snippet to your theme&#8217;s function.php file you can use the following structure to safely display an email address in your post or page content:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>email<span style="color: #009900;">&#93;</span>you<span style="color: #339933;">@</span>you<span style="color: #339933;">.</span>com<span style="color: #009900;">&#91;</span><span style="color: #339933;">/</span>email<span style="color: #009900;">&#93;</span></pre></div></td></tr></table></div>

<p>You can read more about <code>antispambot()</code> in the codex: <a href="http://codex.wordpress.org/Function_Reference/antispambot">http://codex.wordpress.org/Function_Reference/antispambot</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2012/shortcode-to-encode-email-in-wordpress-posts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Log in to WordPress using an Email Address</title>
		<link>http://bavotasan.com/2011/log-in-to-wordpress-using-an-email-address/</link>
		<comments>http://bavotasan.com/2011/log-in-to-wordpress-using-an-email-address/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 16:26:52 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[email address]]></category>
		<category><![CDATA[functions.php]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[username]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3744</guid>
		<description><![CDATA[I needed to figure out how to allow a user to use either their username or email address to log into WordPress. It took a bit of rooting around but the final piece of code ended up being pretty simple. function login_with_email_address&#40;$username&#41; &#123; $user = get_user_by_email&#40;$username&#41;; if&#40;!empty&#40;$user-&#62;user_login&#41;&#41; $username = $user-&#62;user_login; return $username; &#125; add_action&#40;'wp_authenticate','login_with_email_address'&#41;; Place [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to figure out how to allow a user to use either their username or email address to log into WordPress. It took a bit of rooting around but the final piece of code ended up being pretty simple.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> login_with_email_address<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> get_user_by_email<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</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: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_login</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_login</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_authenticate'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'login_with_email_address'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>Place that in your <code>functions.php</code> file and you will be able to sign into your WordPress site using an email address or by default, the username.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2011/log-in-to-wordpress-using-an-email-address/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>HTML5 Placeholder jQuery Fix</title>
		<link>http://bavotasan.com/2011/html5-placeholder-jquery-fix/</link>
		<comments>http://bavotasan.com/2011/html5-placeholder-jquery-fix/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 17:00:45 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[input type]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[placeholder]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3734</guid>
		<description><![CDATA[I was working with placeholder text for the input fields on a recent project and I needed to make sure that the text would appear in all browsers. I had to use a old technique that many of you might be familiar with: &#60;input type=&#34;text&#34; name=&#34;first_name&#34; value=&#34;First Name&#34; onfocus=&#34;if(this.value == 'First Name') { this.value = [...]]]></description>
			<content:encoded><![CDATA[<p>I was working with placeholder text for the input fields on a recent project and I needed to make sure that the text would appear in all browsers. I had to use a old technique that many of you might be familiar with:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;first_name&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;First Name&quot;</span> onfocus<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;if(this.value == 'First Name') { this.value = ''; }&quot;</span> onblur<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;if(this.value == '') { this.value = 'First Name'; }&quot;</span> <span style="color: #339933;">/&gt;</span></pre></div></td></tr></table></div>

<p>That technique uses inline JavaScript to check if the value of the input field matches the default placeholder text. It works in every browser but it does require a lot of extra code on each of your input fields. It would also submit the placeholder text as the value of the input so you would have to place some validation to remove any value that matched the placeholder text. </p>
<p>All of those issues are solved in HTML5 with the <code>placeholder</code> parameter. Now your input tag would just look like this:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;first_name&quot;</span> placeholder<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;First Name&quot;</span> <span style="color: #339933;">/&gt;</span></pre></div></td></tr></table></div>

<p>That does the exact same thing and will not submit a value for the empty input fields. </p>
<p>This HTML5 feature is supported in the following browsers:</p>
<p>Firefox: 3.7+<br />
Safari: 4.0+<br />
Chrome: 4.0+<br />
Opera: 11.0+<br />
iPhone: 4.0+</p>
<p>Since it doesn&#8217;t work in IE and older browsers, you need to use something like this jQuery fix:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #009966; font-style: italic;">/* &lt;![CDATA[ */</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> input <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input&quot;</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><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'placeholder'</span> <span style="color: #000066; font-weight: bold;">in</span> input<span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'[placeholder]'</span><span style="color: #009900;">&#41;</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: #003366; font-weight: bold;">var</span> i <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: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>i.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> i.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'placeholder'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				i.<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: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'placeholder'</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>i.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					i.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'password'</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;">type</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'password'</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;">&#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: #003366; font-weight: bold;">var</span> i <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: #339933;">;</span>	
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>i.<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: #339933;">||</span> i.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> i.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'placeholder'</span><span style="color: #009900;">&#41;</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">type</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'password'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					i.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'password'</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;">type</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'text'</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				i.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'placeholder'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>i.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'placeholder'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</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;">'[placeholder]'</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> i <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: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>i.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> i.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'placeholder'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
					i.<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: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</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>
<span style="color: #009966; font-style: italic;">/* ]]&gt; */</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>First thing it does is check whether the <code>placeholder</code> parameter is supported. If it is, it will do nothing. If it isn&#8217;t it will perform a few things to emulate the HTML5 <code>placeholder</code> parameter. In order to style how your placeholder text appears you can use the following CSS:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.placeholder</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#aaa</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>The fix will also switch the input type to &#8220;text&#8221; for all password inputs so that your placeholder text will not appear as a bunch of black dots. The final part of the fix will empty the value of the input field if it contains the placeholder text so that it is not submitted as a real value in your form.</p>
<p>Since this is a jQuery fix, you need to make sure that you have included a link to jQuery between your head tags:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>With everything in place, you now have a backwards compatible way of using the new HTML5 <code>placeholder</code> parameter so that all of your visitors have the same experience when they are on your site.</p>
<p><strong>Resources:</strong></p>
<p><a href="http://www.webgeekly.com/tutorials/jquery/creating-a-cross-browser-form-field-placeholder/">http://www.webgeekly.com/tutorials/jquery/creating-a-cross-browser-form-field-placeholder/</a><br />
<a href="http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html">http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2011/html5-placeholder-jquery-fix/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>A Better Voting System for WordPress</title>
		<link>http://bavotasan.com/2011/a-better-voting-system-for-wordpress/</link>
		<comments>http://bavotasan.com/2011/a-better-voting-system-for-wordpress/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 11:14:56 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[voting]]></category>
		<category><![CDATA[voting system]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3718</guid>
		<description><![CDATA[I published a tutorial quite a while back called Simple Voting for WordPress with PHP and jQuery. It was not without its problems, and recently I needed to improve on it for a client, so I thought it would be a good idea to finally release an updated version. The original tutorial relied on an [...]]]></description>
			<content:encoded><![CDATA[<p>I published a tutorial quite a while back called <a href="http://bit.ly/aLhLbd">Simple Voting for WordPress with PHP and jQuery</a>. It was not without its problems, and recently I needed to improve on it for a client, so I thought it would be a good idea to finally release an updated version.</p>
<p>The original tutorial relied on an outside PHP file to process the votes but now I use the built-in Ajax function in WordPress. That way it&#8217;s more secure and efficient. To get everything started, let&#8217;s take a look at the jQuery required:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #009966; font-style: italic;">/* &lt;![CDATA[ */</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;#vote&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">not</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.disabled&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> el <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: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> nonce <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#voting_nonce&quot;</span><span style="color: #009900;">&#41;</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: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
			action<span style="color: #339933;">:</span> <span style="color: #3366CC;">'add_votes_options'</span><span style="color: #339933;">,</span>
			nonce<span style="color: #339933;">:</span> nonce<span style="color: #339933;">,</span>
			postid<span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;?php echo $post-&gt;ID; ?&gt;'</span><span style="color: #339933;">,</span>
			ip<span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;?php echo $_SERVER['</span>REMOTE_ADDR<span style="color: #3366CC;">']; ?&gt;'</span>			
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		$.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;?php echo admin_url('</span>admin<span style="color: #339933;">-</span>ajax.<span style="color: #660066;">php</span><span style="color: #3366CC;">'); ?&gt;'</span><span style="color: #339933;">,</span> data<span style="color: #339933;">,</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<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>response<span style="color: #339933;">!=</span><span style="color: #3366CC;">&quot;-1&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				el.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;VOTED&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</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>response<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;null&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;A vote has already been registered to this IP address.&quot;</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: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#votecounter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Thanks for your vote.&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: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;There was a problem registering your vote. Please try again later.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #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: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009966; font-style: italic;">/* ]]&gt; */</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>If the vote button is clicked, it will send the Ajax request and process it accordingly, depending on a few things. The only thing missing, is the code to register a cookie once the vote has been calculated so that voters can only vote once. Let&#8217;s include two cookie functions originally created by <a href="http://www.quirksmode.org/js/cookies.html">Peter-Paul Koch</a> and add a block of code to our original script:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #009966; font-style: italic;">/* &lt;![CDATA[ */</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;">function</span> setCookie<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span>value<span style="color: #339933;">,</span>days<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>days<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #003366; font-weight: bold;">var</span> date <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        date.<span style="color: #660066;">setTime</span><span style="color: #009900;">&#40;</span>date.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>days<span style="color: #339933;">*</span><span style="color: #CC0000;">24</span><span style="color: #339933;">*</span><span style="color: #CC0000;">60</span><span style="color: #339933;">*</span><span style="color: #CC0000;">60</span><span style="color: #339933;">*</span><span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        <span style="color: #003366; font-weight: bold;">var</span> expires <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;; expires=&quot;</span><span style="color: #339933;">+</span>date.<span style="color: #660066;">toGMTString</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: #000066; font-weight: bold;">else</span> <span style="color: #003366; font-weight: bold;">var</span> expires <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
	    document.<span style="color: #660066;">cookie</span> <span style="color: #339933;">=</span> <span style="color: #000066;">name</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #339933;">+</span>value<span style="color: #339933;">+</span>expires<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;; path=/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> getCookie<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #003366; font-weight: bold;">var</span> nameEQ <span style="color: #339933;">=</span> <span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #339933;">;</span>
	    <span style="color: #003366; font-weight: bold;">var</span> ca <span style="color: #339933;">=</span> document.<span style="color: #660066;">cookie</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: #339933;">;</span>
	    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>i <span style="color: #339933;">&lt;</span> ca.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #003366; font-weight: bold;">var</span> c <span style="color: #339933;">=</span> ca<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	        <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>c.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span> c <span style="color: #339933;">=</span> c.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>c.<span style="color: #660066;">length</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>c.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>nameEQ<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> c.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>nameEQ.<span style="color: #660066;">length</span><span style="color: #339933;">,</span>c.<span style="color: #660066;">length</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;">return</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#vote&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">not</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.disabled&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> el <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: #339933;">;</span>
		el.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;span id=&quot;loader&quot;&gt;&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> nonce <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#voting_nonce&quot;</span><span style="color: #009900;">&#41;</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: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
			action<span style="color: #339933;">:</span> <span style="color: #3366CC;">'add_votes_options'</span><span style="color: #339933;">,</span>
			nonce<span style="color: #339933;">:</span> nonce<span style="color: #339933;">,</span>
			postid<span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;?php echo $post-&gt;ID; ?&gt;'</span><span style="color: #339933;">,</span>
			ip<span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;?php echo $_SERVER['</span>REMOTE_ADDR<span style="color: #3366CC;">']; ?&gt;'</span>			
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		$.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;?php echo admin_url('</span>admin<span style="color: #339933;">-</span>ajax.<span style="color: #660066;">php</span><span style="color: #3366CC;">'); ?&gt;'</span><span style="color: #339933;">,</span> data<span style="color: #339933;">,</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<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>response<span style="color: #339933;">!=</span><span style="color: #3366CC;">&quot;-1&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				el.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;VOTED&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</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>response<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;null&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;A vote has already been registered to this IP address.&quot;</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: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#votecounter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Thanks for your vote.&quot;</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;">var</span> cookie <span style="color: #339933;">=</span> getCookie<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;better_votes&quot;</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><span style="color: #339933;">!</span>cookie<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003366; font-weight: bold;">var</span> newcookie <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;?php echo $post-&gt;ID; ?&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003366; font-weight: bold;">var</span> newcookie <span style="color: #339933;">=</span> cookie <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;,&lt;?php echo $post-&gt;ID; ?&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				setCookie<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;better_votes&quot;</span><span style="color: #339933;">,</span> newcookie<span style="color: #339933;">,</span> <span style="color: #CC0000;">365</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: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;There was a problem registering your vote. Please try again later.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #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: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009966; font-style: italic;">/* ]]&gt; */</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>Now a cookie will be registered once the vote has been tallied. This is all the jQuery we need to make our voting system work. If jQuery is not already loaded in your WordPress theme, you may also need to add this into your header.php file before the <code>wp_head()</code> code:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;?</span>php wp_enqueue_script<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'jquery'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">?&gt;</span></pre></div></td></tr></table></div>

<p>The following is the PHP code that we need to process the vote on the server side. This will need to be placed in your theme&#8217;s functions.php file. If the file doesn&#8217;t exist, just create it and make sure this code is placed between the PHP tags:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wp_ajax_add_votes_options&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;add_votes_options&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wp_ajax_nopriv_add_votes_options&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;add_votes_options&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> add_votes_options<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><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;">'nonce'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'voting_nonce'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$postid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'postid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ip'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$voter_ips</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;voter_ips&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$voter_ips</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> <span style="color: #000088;">$voter_ips</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;">&quot;null&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$voter_ips</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">;</span>
		update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;voter_ips&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$voter_ips</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&nbsp;
	<span style="color: #000088;">$current_votes</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;votes&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$new_votes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_votes</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;votes&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_votes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$new_votes</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1</span> ? <span style="color: #000088;">$new_votes</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; votes&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$new_votes</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; vote&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>The two action calls at the beginning hook into the Ajax function from the jQuery. We need both since one is for logged-in users and the other is for guests. Next we check for the security nonce, and end the process if it is not set correctly. This is a huge improvement over my old code that had absolutely no security whatsoever. If all is good, we start processing the vote by checking if the voters IP address has already been registered. If so, the process stops and returns a &#8220;null&#8221; value. Otherwise we registered the vote and IP address and echo out the total votes.</p>
<p>If you take a look at the jQuery above, you can see how the different responses will be processed. A &#8220;null&#8221; response will alert the voter that their IP address has already been registered so their new vote will not count. A response of &#8220;-1&#8243; means something went wrong and we alert the voter. If everything goes well, the vote is registered, the voter is thanked and the total number of votes increases on the page.</p>
<p>There you have all the jQuery and PHP required to get it working on the backend, but you still need some PHP/HTML in order for things to work on the front end.</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div 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;">// This will display &quot;0 votes&quot; and increase as votes are added</span>
<span style="color: #000088;">$votes</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;votes&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$votes</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$votes</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$votes</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$votes</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$plural</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #000088;">$plural</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;s&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div id=&quot;votecounter&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$votes</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' vote'</span><span style="color: #339933;">.</span><span style="color: #000088;">$plural</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// This will display the vote button and disable it if a cookie has already</span>
<span style="color: #666666; font-style: italic;">// been set. We also add the security nonce here. </span>
<span style="color: #000088;">$hasvoted</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'better_votes'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hasvoted</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hasvoted</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: #990000;">in_array</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: #339933;">,</span> <span style="color: #000088;">$hasvoted</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$vtext</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;VOTED&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$class</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' class=&quot;disabled&quot;'</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;">$vtext</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;VOTE&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$class</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;a href=&quot;javascript:void(0)&quot; id=&quot;vote&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$class</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$vtext</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_nonce_field'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> wp_nonce_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'voting_nonce'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'voting_nonce'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>So there you have it, a more efficient voting system for WordPress that is secure and will hopefully double guard you against fraudulent voting. You can see this working live on the new <a href="http://2011.bloodshotscanada.com">Bloodshots</a> website. It will only be active between Oct 24th and Oct 28th while people can vote for the films.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2011/a-better-voting-system-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>An Even Better Author List in WordPress</title>
		<link>http://bavotasan.com/2011/an-even-better-author-list-in-wordpress/</link>
		<comments>http://bavotasan.com/2011/an-even-better-author-list-in-wordpress/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 17:11:32 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Authors]]></category>
		<category><![CDATA[contributors]]></category>
		<category><![CDATA[get_users()]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3665</guid>
		<description><![CDATA[I already wrote about this a while back in &#8220;How to Display an Author List with Avatars in WordPress&#8221; but I recently realized that it needed updating. There&#8217;s a better way of collecting and displaying all the information and you can also add a few variables to give you more control over the output. Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2011/09/author_big.jpg" alt="" title="author_big" width="550" height="200" class="aligncenter size-full wp-image-3682" />I already wrote about this a while back in <a href="http://bavotasan.com/2009/how-to-display-an-author-list-with-avatars-in-wordpress/">&#8220;How to Display an Author List with Avatars in WordPress&#8221;</a> but I recently realized that it needed updating. There&#8217;s a better way of collecting and displaying all the information and you can also add a few variables to give you more control over the output.</p>
<p>Let&#8217;s start off with creating our variables:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$display_admins</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$order_by</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'display_name'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count'</span>
<span style="color: #000088;">$role</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 'subscriber', 'contributor', 'editor', 'author' - leave blank for 'all'</span>
<span style="color: #000088;">$avatar_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hide_empty</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// hides authors with zero posts</span></pre></div></td></tr></table></div>

<p>Next we can add the code to gather our contributors:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$display_admins</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$blogusers</span> <span style="color: #339933;">=</span> get_users<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'orderby='</span><span style="color: #339933;">.</span><span style="color: #000088;">$order_by</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;role='</span><span style="color: #339933;">.</span><span style="color: #000088;">$role</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$admins</span> <span style="color: #339933;">=</span> get_users<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'role=administrator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$exclude</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;">$admins</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ad</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$exclude</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ad</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$exclude</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;">$exclude</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$blogusers</span> <span style="color: #339933;">=</span> get_users<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'exclude='</span><span style="color: #339933;">.</span><span style="color: #000088;">$exclude</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;orderby='</span><span style="color: #339933;">.</span><span style="color: #000088;">$order_by</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;role='</span><span style="color: #339933;">.</span><span style="color: #000088;">$role</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$authors</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;">$blogusers</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$bloguser</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> get_userdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bloguser</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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hide_empty</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$numposts</span> <span style="color: #339933;">=</span> count_user_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$numposts</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$authors</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>Now that we have all the information we need, let&#8217;s display it:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;ul class=&quot;contributors&quot;&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authors</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$author</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$display_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$author</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'display_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$avatar</span> <span style="color: #339933;">=</span> get_avatar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$author</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;">$avatar_size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$author_profile_url</span> <span style="color: #339933;">=</span> get_author_posts_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$author</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;a href=&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$author_profile_url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$avatar</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;a href=&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$author_profile_url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot; class=&quot;contributor-link&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</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: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span></pre></div></td></tr></table></div>

<p>If we put all the code together we get the following:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$display_admins</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$order_by</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'display_name'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count'</span>
<span style="color: #000088;">$role</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 'subscriber', 'contributor', 'editor', 'author' - leave blank for 'all'</span>
<span style="color: #000088;">$avatar_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hide_empty</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// hides authors with zero posts</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$display_admins</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$blogusers</span> <span style="color: #339933;">=</span> get_users<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'orderby='</span><span style="color: #339933;">.</span><span style="color: #000088;">$order_by</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;role='</span><span style="color: #339933;">.</span><span style="color: #000088;">$role</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$admins</span> <span style="color: #339933;">=</span> get_users<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'role=administrator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$exclude</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;">$admins</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ad</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$exclude</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ad</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$exclude</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;">$exclude</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$blogusers</span> <span style="color: #339933;">=</span> get_users<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'exclude='</span><span style="color: #339933;">.</span><span style="color: #000088;">$exclude</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;orderby='</span><span style="color: #339933;">.</span><span style="color: #000088;">$order_by</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;role='</span><span style="color: #339933;">.</span><span style="color: #000088;">$role</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$authors</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;">$blogusers</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$bloguser</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> get_userdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bloguser</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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hide_empty</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$numposts</span> <span style="color: #339933;">=</span> count_user_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$numposts</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$authors</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;ul class=&quot;contributors&quot;&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authors</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$author</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$display_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$author</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'display_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$avatar</span> <span style="color: #339933;">=</span> get_avatar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$author</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;">$avatar_size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$author_profile_url</span> <span style="color: #339933;">=</span> get_author_posts_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$author</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;a href=&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$author_profile_url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$avatar</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;a href=&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$author_profile_url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot; class=&quot;contributor-link&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</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: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></td></tr></table></div>

<p>All it needs is a little CSS to style it:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.contributors</span> <span style="color: #6666ff;">.avatar</span> <span style="color: #00AA00;">&#123;</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;">clear</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">both</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
	border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
	box-sizing<span style="color: #00AA00;">:</span> content-box<span style="color: #00AA00;">;</span> 
	-moz-box-sizing<span style="color: #00AA00;">:</span> content-box<span style="color: #00AA00;">;</span> 
	-webkit-box-sizing<span style="color: #00AA00;">:</span> content-box<span style="color: #00AA00;">;</span> 
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.contributors</span> <span style="color: #6666ff;">.avatar</span><span style="color: #3333ff;">:hover  </span><span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#999</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.contributors</span> <span style="color: #6666ff;">.contributor-link</span> <span style="color: #00AA00;">&#123;</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;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>You can play around with the CSS to get it looking the way you want and with the variables in place, you can control exactly what type of author list will be displayed.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2011/an-even-better-author-list-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Adding an Inset Shadow to an Image Using CSS3</title>
		<link>http://bavotasan.com/2011/adding-inset-shadow-to-image-css3/</link>
		<comments>http://bavotasan.com/2011/adding-inset-shadow-to-image-css3/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 14:18:32 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[image shadow]]></category>
		<category><![CDATA[inset shadow]]></category>
		<category><![CDATA[presswork]]></category>
		<category><![CDATA[socialstock]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3652</guid>
		<description><![CDATA[Yesterday PressWork launched a new theme in conjunction with Empire Avenue. The original design had a really nice shadow effect on the images and I wanted to make sure that I could code it using CSS3. The problem was, CSS3 inset shadows don&#8217;t work at all on images. The only way to get the effect [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday <a href="http://presswork.me" title="A Simple Fade with CSS3">PressWork</a> launched a new theme in conjunction with <a href="http://empireavenue.com/">Empire Avenue</a>. The original design had a really nice shadow effect on the images and I wanted to make sure that I could code it using CSS3. The problem was, CSS3 inset shadows don&#8217;t work at all on images. The only way to get the effect to work is to use the <code>::before</code> selector to add a container that can be positioned above the image.</p>
<p>This is how the HTML should look:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://presswork.me/themes/socialstock/&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;img-shadow&quot;</span><span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://presswork.me/wp-content/uploads/2011/09/socialstock_home.jpg&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>That will display an image surrounded by an anchor tag.</p>
<p>Here is the CSS3 we need:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.img-shadow</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">max-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</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: #00AA00;">&#125;</span>
&nbsp;
    <span style="color: #6666ff;">.img-shadow</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:before </span><span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">inset</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">8px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span>.6<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		-moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">inset</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">8px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span>.6<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">inset</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">8px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span>.6<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	   <span style="color: #00AA00;">&#125;</span> 
&nbsp;
<span style="color: #6666ff;">.img-shadow</span> img <span style="color: #00AA00;">&#123;</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: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>Here is a live example:</p>
<p><a href="http://presswork.me/themes/socialstock/" class="img-shadow"><img src="http://presswork.me/wp-content/uploads/2011/09/socialstock_home.jpg" alt="" /></a></p>
<p><br class="clear" /></p>
<p>The only concern anyone might have when using this effect is that the container must use the float style in order for it to work properly. If anyone can find a better solution please leave a comment below.</p>
<p>You can also take a look at the <a href="http://demos.presswork.me/socialstock/">SocialStock theme demo</a> to see it working on multiple images.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2011/adding-inset-shadow-to-image-css3/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Create a Black &amp; White Thumbnail in WordPress</title>
		<link>http://bavotasan.com/2011/create-black-white-thumbnail-wordpress/</link>
		<comments>http://bavotasan.com/2011/create-black-white-thumbnail-wordpress/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 18:37:52 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[black and white]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[thumbnails]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3641</guid>
		<description><![CDATA[A while back I worked on a site that required a hover effect where a black and white image faded into a color image. I wrote a tutorial called Creating a Mouseover Fade Effect with jQuery on the jQuery technique I used for the hover. That effect no longer requires jQuery since we can now [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://bavotasan.com/wp-content/uploads/2011/09/colorballs_big.jpg" alt="" title="colorballs_big" width="550" height="200" class="aligncenter size-full wp-image-3649" />A while back I worked on a site that required a hover effect where a black and white image faded into a color image. I wrote a tutorial called <a href="http://bavotasan.com/2009/creating-a-jquery-mouseover-fade-effect/" title="Creating a Mouseover Fade Effect with jQuery">Creating a Mouseover Fade Effect with jQuery</a> on the jQuery technique I used for the hover. That effect no longer requires jQuery since we can now use CSS3 transitions (see <a href="http://bavotasan.com/2011/a-simple-fade-with-css3/" title="A Simple Fade with CSS3">A Simple Fade with CSS3</a>) but the real issue was with having to upload two separate images to get the effect to work, which required an image editing software like Photoshop. Thankfully, <a href="http://ottopress.com/2011/customizing-wordpress-images/">Otto</a> just wrote a great article on a way that you can use some built in WordPress functions and a little PHP to automatically create a black and white thumbnail when you upload an image. </p>
<p>First we need to create a new thumbnail using <code>add_image_size()</code>. We&#8217;ll use the same thumbnail settings from the WordPress Media page in the wp-admin. Add this to your functions.php file within the PHP tags:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'after_setup_theme'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'bw_images_size'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> bw_images_size<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$crop</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumbnail_crop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span> ? <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	add_image_size<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumbnail-bw'</span><span style="color: #339933;">,</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumbnail_size_w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumbnail_size_h'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$crop</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>With that in place, we can now add the following function which will automatically create a black and white thumbnail:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_generate_attachment_metadata'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'bw_images_filter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> bw_images_filter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$meta</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> wp_upload_dir<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> trailingslashit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$meta</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sizes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'thumbnail-bw'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orig_w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$orig_h</span><span style="color: #339933;">,</span> <span style="color: #000088;">$orig_type</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> wp_load_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">imagefilter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span> IMG_FILTER_GRAYSCALE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);</span>
	<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$orig_type</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> IMAGETYPE_GIF<span style="color: #339933;">:</span>
			<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.gif&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-bw.gif&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> IMAGETYPE_PNG<span style="color: #339933;">:</span>
			<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.png&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-bw.png&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> IMAGETYPE_JPEG<span style="color: #339933;">:</span>
			<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.jpg&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-bw.jpg&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$meta</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>Whenever you upload an image, this function will create a new black and white thumbnail automatically. I also added a Gaussian Blur but commented it out. Remove those two slashes &#8220;//&#8221; to add a Gaussian Blur to your new black and white thumbnail. See other <a href="http://php.net/manual/en/function.imagefilter.php">available filters</a>.</p>
<p>Once you&#8217;ve added the above code, you can use <code>get_post_thumbnail()</code> within your WordPress loop to display the two images for the effect:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'has_post_thumbnail'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> has_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; class=&quot;fade-image&quot;&gt;'</span><span style="color: #339933;">;</span>
	the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumbnail-bw'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'fade-image-a'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumbnail'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'fade-image-b'</span><span style="color: #009900;">&#41;</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;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></td></tr></table></div>

<p>This displays both images and surrounds them by an anchor tag. All we need is a little CSS3 to get our fade working:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.fade-image</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;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	.fade-image-a<span style="color: #00AA00;">,</span>
	<span style="color: #6666ff;">.fade-image</span> b <span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.fade-image-a</span> <span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">5</span><span style="color: #00AA00;">;</span>
		opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
		transition<span style="color: #00AA00;">:</span> opacity .25s ease-in-out<span style="color: #00AA00;">;</span>
		-moz-transition<span style="color: #00AA00;">:</span> opacity .25s ease-in-out<span style="color: #00AA00;">;</span>
		-webkit-transition<span style="color: #00AA00;">:</span> opacity .25s ease-in-out<span style="color: #00AA00;">;</span>
   		<span style="color: #00AA00;">&#125;</span>	
&nbsp;
		<span style="color: #6666ff;">.fade-image-a</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
			opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
			<span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p><a href="javascript:void(0)" class="fade-image"><img src="http://bavotasan.com/wp-content/uploads/2011/09/colorballs-bw.jpg" class="fade-image-a" alt="" /><img src="http://bavotasan.com/wp-content/uploads/2011/09/colorballs.jpg" class="fade-image-b" alt="" /></a></p>
<p>The fade will only work in browsers that support CSS3 transitions but everything else should work on any server that supports the latest release of WordPress.</p>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2011/create-black-white-thumbnail-wordpress/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>A Simple Fade with CSS3</title>
		<link>http://bavotasan.com/2011/a-simple-fade-with-css3/</link>
		<comments>http://bavotasan.com/2011/a-simple-fade-with-css3/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 15:39:51 +0000</pubDate>
		<dc:creator>c.bavota</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[fade]]></category>
		<category><![CDATA[fade effect]]></category>
		<category><![CDATA[jquery fade effect]]></category>
		<category><![CDATA[opacity]]></category>
		<category><![CDATA[transition]]></category>

		<guid isPermaLink="false">http://bavotasan.com/?p=3620</guid>
		<description><![CDATA[There was a time when the only way to fade an element or image was by using JavaScript/jQuery (see Creating a Mouseover Fade Effect with jQuery). With CSS3, you can easily create a fade effect with nothing more than a little CSS. Let&#8217;s start with a text element: &#60;p class=&#34;fade&#34;&#62;This is my text element that [...]]]></description>
			<content:encoded><![CDATA[<p>There was a time when the only way to fade an element or image was by using JavaScript/jQuery (see <a href="http://bavotasan.com/2009/creating-a-jquery-mouseover-fade-effect/">Creating a Mouseover Fade Effect with jQuery</a>). With CSS3, you can easily create a fade effect with nothing more than a little CSS.</p>
<p>Let&#8217;s start with a text element:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>p <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;fade&quot;</span><span style="color: #339933;">&gt;</span>This is my text element that will fade when you hover over it<span style="color: #339933;">.&lt;/</span>p<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>Now comes the CSS3:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.fade</span> <span style="color: #00AA00;">&#123;</span>
   opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
   transition<span style="color: #00AA00;">:</span> opacity .25s ease-in-out<span style="color: #00AA00;">;</span>
   -moz-transition<span style="color: #00AA00;">:</span> opacity .25s ease-in-out<span style="color: #00AA00;">;</span>
   -webkit-transition<span style="color: #00AA00;">:</span> opacity .25s ease-in-out<span style="color: #00AA00;">;</span>
   <span style="color: #00AA00;">&#125;</span>
&nbsp;
   <span style="color: #6666ff;">.fade</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
      opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">;</span>
      <span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>Hover over the text below to see a live demo:</p>
<p class="fade">This is my text element that will fade when you hover over it.</p>
<p>Let&#8217;s do the same thing with an image:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://bavotasan.com/wp-content/uploads/2011/09/fadeimage.jpg&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;200&quot;</span> height<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;150&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;fade&quot;</span> <span style="color: #339933;">/&gt;</span></pre></div></td></tr></table></div>

<p>Hover over the image below to see it in action:</p>
<p><img src="http://bavotasan.com/wp-content/uploads/2011/09/fadeimage.jpg" alt="" width="200" height="150" class="fade" /></p>
<p>We can also set it up so that a background color fades in. Let&#8217;s create a simple menu using an unordered list:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ul <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nav-fade&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Home<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Tutorials<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Articles<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></div></td></tr></table></div>

<p>Now for the CSS3:</p>

<div class="wp_syntax"><table border='0' cellpadding='0' cellspacing='0'><tr><td><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.nav-fade</span> li <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
   transition<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">background</span> .25s ease-in-out<span style="color: #00AA00;">;</span>
   -moz-transition<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">background</span> .25s ease-in-out<span style="color: #00AA00;">;</span>
   -webkit-transition<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">background</span> .25s ease-in-out<span style="color: #00AA00;">;</span>
   <span style="color: #00AA00;">&#125;</span>
&nbsp;
   <span style="color: #6666ff;">.nav-fade</span> li<span style="color: #3333ff;">:hover </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;">#ddd</span><span style="color: #00AA00;">;</span>
      <span style="color: #00AA00;">&#125;</span></pre></div></td></tr></table></div>

<p>Let&#8217;s see it live:</p>
<ul class="nav-fade">
<li>Home</li>
<li>Tutorials</li>
<li>Articles</li>
</ul>
<p>As you can see, there are quite a few possibilities when it comes to using CSS3 to create a simple fade effect. As always, remember that CSS3 only works on modern browsers.</p>
<p><strong>Resources</strong></p>
<ul>
<li><a href="http://www.w3schools.com/css3/css3_transitions.asp">CSS3 Transitions</a></li>
<li><a href="http://www.w3.org/TR/css3-transitions/">CSS Transitions Module Level 3</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://bavotasan.com/2011/a-simple-fade-with-css3/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

