<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Flowdrops</title>
	
	<link>http://www.flowdrops.com</link>
	<description>The Cool Dude Who Does Cool Things With WordPress</description>
	<lastBuildDate>Fri, 27 Aug 2010 10:42:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Flowdrops" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="flowdrops" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>10 Useful Code Snippets For Your WordPress Theme Functions.php File</title>
		<link>http://www.flowdrops.com/blog/2010/05/10-useful-code-snippets-for-your-wordpress-theme-functions-php-file/</link>
		<comments>http://www.flowdrops.com/blog/2010/05/10-useful-code-snippets-for-your-wordpress-theme-functions-php-file/#comments</comments>
		<pubDate>Sun, 16 May 2010 14:11:18 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/blog/?p=374</guid>
		<description><![CDATA[I&#8217;m working with a lot of WordPress based sites and there are some code snippets which I frequently use. I want to share them with you. 1. Prevent Direct File Access # No direct file load if &#40;!empty&#40;$_SERVER&#91;'SCRIPT_FILENAME'&#93;&#41; &#38;&#38; 'functions.php' &#8230; <a href="http://www.flowdrops.com/blog/2010/05/10-useful-code-snippets-for-your-wordpress-theme-functions-php-file/">Read post <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working with a lot of WordPress based sites and there are some code snippets which I frequently use. I want to share them with you.</p>
<h2>1. Prevent Direct File Access</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># No direct file load
</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;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">'functions.php'</span> <span style="color: #339933;">==</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'He\'s dead, Jim!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Put this code on the top of your functions.php file. It prevents users from directly accessing it via URL (http://yourblog.com/wp-content/themes/yourtheme/functions.php).</p>
<h2>2. Set Debugging Variables</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Debugging
</span><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'IS_SITE_DEBUG'</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: #666666; font-style: italic;">// Really up to you how you use this variable</span>
<span style="color: #990000;">error_reporting</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">E_ALL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Shows ALL PHP errors. Set to 0 on a live site</span></pre></div></div>

<p>Mostly when I create new themes, I set up a debug environment too. It helps me find possible errors more easy. The variable &#8216;IS_SITE_DEBUG&#8217; is really helpful here. It allows the output of additional debug information while developing a theme. For ex. I always output some WP internal stuff like the current <a href="http://codex.wordpress.org/Function_Reference/WP_Query" target="_blank">wp_query</a> object in separate DIV’s.</p>
<h2>3. File Paths</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Template directory, includes Win/XAMPP compatibility
</span><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'CURRENT_TEMPLATE_DIR'</span><span style="color: #339933;">,</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'\\'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> get_template_directory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I&#8217;m developing on Windows, so I need those backslashes replaced.</p>
<h2>4. Theme Header</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Set up the WordPress theme header
</span><span style="color: #000000; font-weight: bold;">function</span> my_custom_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># Add a custom Stylesheet
</span>	wp_enqueue_style<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'yui_reset'</span><span style="color: #339933;">,</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/css/reset-min.css'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2.7.0'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'screen'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;"># Add custom JavaScript
</span>	wp_enqueue_script<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'js_main'</span><span style="color: #339933;">,</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/js/js_main.js'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'jquery'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jquery-ui-core'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jquery-ui-tabs'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.0.0'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;"># Add only if on front end, never on /wp-admin/
</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> is_admin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_custom_header'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Instead of adding all required Stylesheets &amp; Scripts into your header.php file, you can add them to your functions file. This also allows you to define dependencies of your scripts, like jQuery, which will automagically be added to the header as well. Requires <a href="http://codex.wordpress.org/Theme_Development#Plugin_API_Hooks" target="_blank">wp_head();</a> to be called in your theme’s header. More info on <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_style" target="_blank">wp_enqueue_style</a> and <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script" target="_blank">wp_enqueue_script</a>.</p>
<h2>5. Custom Functions / Template Tags</h2>

<div class="wp_syntax"><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;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'getAdvertisings'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> getAdvertisings<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$ads</span> <span style="color: #339933;">=</span> get_bookmarks<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'category_name=advertisings&amp;amp;limit='</span><span style="color: #339933;">.</span><span style="color: #000088;">$limit</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ads</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Creating custom functions or <a href="http://codex.wordpress.org/Template_Tags/" target="_blank">template tags</a> can save you a lot of time and there’s absolutely no limit on the use. From returning a simple object with posts like the example above to custom data to…whatever comes to your mind. You can then use these functions anywhere in your theme with a simple call to the function.</p>
<h2>6. Helpers</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> is_even_number<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</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>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Helpers are useful if you have to want to output something depending on a condition. The above example can be used to iterate through items and depending on the current item counter is even or odd, maybe output the item in a different color (think of colored table rows for ex.).</p>
<h2>7. Prevent Access To WP-Admin</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Disable access to wp-admin for Subscribers
</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_user_logged_in<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> is_admin<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: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$current_user</span><span style="color: #339933;">;</span>
    get_currentuserinfo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user_info</span> <span style="color: #339933;">=</span> get_userdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user_info</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wp_user_level</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span>get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/wp-login.php?redirect='</span><span style="color: #339933;">.</span>get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/wp-admin/'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Personally I think subscribers should not be allowed access to /wp-admin/. The above example does exactly this. You can change the <a href="http://codex.wordpress.org/Roles_and_Capabilities#User_Levels" target="_blank">wp_user_level</a> variable to another role if you want to prevent other users from accessing the back end.</p>
<h2>8. No External Stuff While Working Locally</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> is_live_site<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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$_live_site_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;www.flowdrops.com&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$_compare_to</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_live_site_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_compare_to</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pos</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I use this function mostly in the footer. I don&#8217;t want to load Google Analytics or other external stuff while working on the localhost.</p>
<h2>9. Validate Email Address</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> is_email_valid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mx_lookup</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">eregi</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mx_lookup</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;@&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #990000;">getmxrr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mxrecords</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: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Sometimes you need to validate email addresses. I find this function very useful (credits to <a href="http://webdeveloperplus.com" target="_blank">http://webdeveloperplus.com</a>)</p>
<h2>10. Shortened URLs</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_tiny_url<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$url</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$tiny_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;http://tinyurl.com/api-create.php?url=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$tiny_url</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Very useful if you want to include a shortened URL of your post somewhere.</p>
<h2>Note</h2>
<p>As a best practice always check if the function name is unused by adding</p>
<pre>if (!function_exists('your_function_name'))</pre>
<p>around your functions (see #5) and <a href="http://php.net/manual/en/function.function-exists.php" target="_blank">PHP Docs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2010/05/10-useful-code-snippets-for-your-wordpress-theme-functions-php-file/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Re-numbering With jQuery</title>
		<link>http://www.flowdrops.com/blog/2009/08/re-numbering-with-jquery/</link>
		<comments>http://www.flowdrops.com/blog/2009/08/re-numbering-with-jquery/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 10:29:13 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Code Snippet]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=300</guid>
		<description><![CDATA[I needed this to do a quick re-numbering of featured items in a slider on the homepage because I was always changing the PHP code and the numbering got messed up. Code to do a quick re-numbering of &#8216;a span&#8217; &#8230; <a href="http://www.flowdrops.com/blog/2009/08/re-numbering-with-jquery/">Read post <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I needed this to do a quick re-numbering of featured items in a slider on the homepage because I was always changing the PHP code and the numbering got messed up.</p>
<p>Code to do a quick re-numbering of &#8216;a span&#8217; items in a unordered list:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    renumber_featured_nav<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> renumber_featured_nav<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> ftabscount <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;li.ftab a span&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>ftabscount<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        ftabscount<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></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2009/08/re-numbering-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip: Exclude Categories From Archive In WordPress</title>
		<link>http://www.flowdrops.com/blog/2009/08/tip-exclude-categories-from-archive-in-wordpress/</link>
		<comments>http://www.flowdrops.com/blog/2009/08/tip-exclude-categories-from-archive-in-wordpress/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 08:53:13 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[custom_query]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[query_posts]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=292</guid>
		<description><![CDATA[While working on a recent project, I came across a task: exclude certain categories from the archive page. I went the usual way to the WordPress codex -> query_posts and thought the following would do it: 1 2 3 4 &#8230; <a href="http://www.flowdrops.com/blog/2009/08/tip-exclude-categories-from-archive-in-wordpress/">Read post <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While working on a recent project, I came across a task: exclude certain categories from the archive page. I went the usual way to the WordPress codex -> <a href="http://codex.wordpress.org/Template_Tags/query_posts" target="_blank">query_posts</a> and thought the following would do it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Exclude categories | archive.php
</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'two'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$current_cat</span> <span style="color: #339933;">=</span> get_query_var<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'cat'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$exclude_cat</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$current_page</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> get_query_var<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'paged'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> ? get_query_var<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'paged'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cat=<span style="color: #006699; font-weight: bold;">$current_cat</span>,-<span style="color: #006699; font-weight: bold;">$exclude_cat</span>&amp;paged=<span style="color: #006699; font-weight: bold;">$current_page</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//The Loop</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This, unfortunately, didn&#8217;t work. I then thought of filtering via <a href="http://codex.wordpress.org/Custom_Queries" target="_blank">custom queries</a>. The problem with custom queries is that the filter is applied to each and every query on the page. If you do:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Exclude categories | functions.php
</span><span style="color: #000000; font-weight: bold;">function</span> fd_remove_cat<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$nada</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'two'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query_vars</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'-3'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pre_get_posts'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'fd_remove_cat'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>this will work, but it affects all other queries on the page as well. If you have some custom &#8216;query_posts&#8217; in your theme, category 3 will be stripped out of all queries on the page.</p>
<p>I came up with this solution:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Exclude categories | archive.php
</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'two'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$paged</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> get_query_var<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'paged'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> ? get_query_var<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'paged'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    query_posts<span style="color: #009900;">&#40;</span>
        <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span>
            <span style="color: #990000;">array</span>
            <span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'category__in'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'category__not_in'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'paged'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$paged</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//The Loop</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The above code preserves the original query and adds/alter defined query variables (also see <a href="http://codex.wordpress.org/Template_Tags/query_posts#Preserving_the_Original_Query" target="_blank">query_posts</a>, &#8216;Preserving the Original Query&#8217;).</p>
<p>I hope this post keeps you from wasting time while trying to alter the wp_query.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2009/08/tip-exclude-categories-from-archive-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Adding Facebook Connect to your WordPress Blog</title>
		<link>http://www.flowdrops.com/blog/2009/08/adding-facebook-connect-to-your-wordpress-blog/</link>
		<comments>http://www.flowdrops.com/blog/2009/08/adding-facebook-connect-to-your-wordpress-blog/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 10:45:08 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[WP-FBConnect]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=285</guid>
		<description><![CDATA[Today I added &#8216;Facebook Connect&#8216; to my blog and I was running into two or three caveats. I want to share my trial-and-error experience from today with you. First, I downloaded the WP-FBConnect plugin, installed &#38; activated it in the &#8230; <a href="http://www.flowdrops.com/blog/2009/08/adding-facebook-connect-to-your-wordpress-blog/">Read post <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I added &#8216;<a href="http://developers.facebook.com/connect.php" target="_blank">Facebook Connect</a>&#8216; to my blog and I was running into two or three caveats. I want to share my trial-and-error experience from today with you.</p>
<p>First, I downloaded the <a href="http://wordpress.org/extend/plugins/wp-facebookconnect/" target="_blank">WP-FBConnect</a> plugin, installed &amp; activated it in the wp-admin. After reading myself trough <a href="http://wiki.developers.facebook.com/index.php/WP-FBConnect" target="_blank">the Wiki</a> and <a href="http://www.adambreckler.com/setting-up-facebook-connect-for-wordpress" target="_blank">Adam Breckler&#8217;s tutorial</a> I was ready to set up the required <a href="http://www.facebook.com/developers/createapp.php" target="_blank">Facebook Application</a>.</p>
<p>Having entered only the minimal required information to get the WP-FBConnect plugin up and running, I tried to login to my site with my Facebook account. It worked fine and I was able to post a comment.</p>
<p>After that I wanted to do some customizations and here&#8217;s where the problems started:</p>
<ul>
<li><strong><em>Infinite redirect loop when trying to log out</em></strong><br />
Reason: <a href="http://forum.developers.facebook.com/viewtopic.php?id=32640">http://forum.developers.facebook.com/viewtopic.php?id=32640</a><br />
Solution: Clear all your browser cookies (or at least all cookies from the affected domain). Don&#8217;t use the &#8216;base domain&#8217; field in the Facebook Application settings.</li>
<li><strong><em>Logged in as &#8220;Facebook User&#8221;, Username is not displaying correctly</em></strong><br />
Reason: <a href="http://wordpress.org/support/topic/234687" target="_blank">http://wordpress.org/support/topic/234687</a> (first post from <a href="http://www.facebook.com/AHupp" target="_blank">ahupp</a>). You may also want to read <a href="http://forum.developers.facebook.com/viewtopic.php?id=36527" target="_blank">this post</a>.</li>
<li><strong><em>Facebook users have access to wp-admin</em></strong><br />
This was the biggest issue as I really don&#8217;t want to expose anything from the WP back-end to &#8216;Subscribers&#8217;. My solution is simple: add the following code to your themes &#8216;functions.php&#8217;:</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Disable access to wp-admin for Facebook users
</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_admin<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: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$current_user</span><span style="color: #339933;">;</span>
    get_currentuserinfo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user_info</span> <span style="color: #339933;">=</span> get_userdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_info</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fbuid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'No access for Facebook users!'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you want to change the appearance of the FB login button, you can do so by updating the code at line 99 of &#8216;common.php&#8217; according to the attributes <a href="http://wiki.developers.facebook.com/index.php/Facebook_Connect_Login_Buttons" target="_blank">described here</a>.</p>
<p>If you run into more issues with the plugin, please read the section &#8216;Troubleshooting / FAQ&#8217; outlined in <a href="http://wiki.developers.facebook.com/index.php/WP-FBConnect" target="_blank">this document</a>.</p>
<p>Happy Facebook-Connecting!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2009/08/adding-facebook-connect-to-your-wordpress-blog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Include WordPress Author Biographical Info In Posts</title>
		<link>http://www.flowdrops.com/blog/2009/07/include-wordpress-author-biographical-info-in-posts/</link>
		<comments>http://www.flowdrops.com/blog/2009/07/include-wordpress-author-biographical-info-in-posts/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 08:17:46 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Worth A Read]]></category>
		<category><![CDATA[Themes]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=279</guid>
		<description><![CDATA[In addition to this and this post, I thought this post may be useful for you as well. It describes how you can add the &#8216;Biographical Info&#8217; to your posts.]]></description>
			<content:encoded><![CDATA[<p>In addition to <a href="http://www.flowdrops.com/blog/wordpress/guest-posts-and-the_author-in-your-wordpress-blog/" target="_blank">this</a> and <a href="http://catalyticat.com/adding-a-biography-to-your-wordpress-posts" target="_blank">this</a> post, I thought <a href="http://wphacks.com/how-to-add-bio-info-to-wordpress-posts/" target="_blank">this post</a> may be useful for you as well. It describes how you can add the &#8216;Biographical Info&#8217; to your posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2009/07/include-wordpress-author-biographical-info-in-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic form elements &amp; the jQuery validation plugin</title>
		<link>http://www.flowdrops.com/blog/2009/04/dynamic-form-elements-the-jquery-validation-plugin/</link>
		<comments>http://www.flowdrops.com/blog/2009/04/dynamic-form-elements-the-jquery-validation-plugin/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 17:50:57 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Dynamic Forms]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=228</guid>
		<description><![CDATA[I recently run into a problem where I had to validate a form with dynamic fields. I am impressed of the jQuery Validation plugin but I had no clue on how to achieve this as the documentation does not have &#8230; <a href="http://www.flowdrops.com/blog/2009/04/dynamic-form-elements-the-jquery-validation-plugin/">Read post <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently run into a problem where I had to validate a form with dynamic fields. I am impressed of the <a href="http://plugins.jquery.com/project/validate" target="_blank">jQuery Validation plugin</a> but I had no clue on how to achieve this as the documentation does not have any code on this included. A few searches on in the WWW didn’t bring the right results, but I eventually found some snippet in the Google Groups (I forgot where, sorry).</p>
<p>Now, let’s say you have a form with a few elements and depending on their selection or values one or more fields are added to the form:</p>
<p><a href="http://www.flowdrops.com/demos/jquery/validation/dynamic-forms/" target="_blank">View a basic sample/demo form here</a></p>
<p>Since you cannot validate a hidden element (because the user can’t make a selection or enter anything), you cannot add validation rules. You need to add/remove this rules dynamic depending on the user’s input.</p>
<p>Actually, the code is very simple. All you have to do is to catch the ‘change’, ‘blur’ or whatever event from the ‘other’ element and attach a simple function to add the validation rule. To go with the demo form this is it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[name='howhelp']&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[name='howhelp']:checked&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: #3366CC;">&quot;help&quot;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#whathelp&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">rules</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;add&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#problems&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span>
  <span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#whathelp&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">rules</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;remove&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#problems&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Simple. Let’s see what the code does line for line:</p>
<ul>
<li>line 1 tells to fire a function if the radiobuttons status have changed</li>
<li>line 3 checks if the current selected radiobutton’s value is equal to ‘help’</li>
<li>line 5 adds the validation rule to the hidden select ‘whathelp’</li>
<li>line 6 shows the hidden select</li>
<li>the rest removes the validation rule and hides the select, in this case the value was not equal to ‘help’</li>
</ul>
<p>With this code, you can validate pretty much any complex form with the validate plugin.</p>
<p>Further reading:</p>
<ul>
<li><a href="http://www.flowdrops.com/demos/jquery/validation/dynamic-forms/" target="_blank">Demo form</a></li>
<li><a href="http://jquery.com/" target="_blank">jQuery</a></li>
<li><a href="http://plugins.jquery.com/project/validate" target="_blank">jQuery Validation plugin</a></li>
<li><a href="http://docs.jquery.com/Plugins/Validation" target="_blank">jQuery Validation plugin (documentation)</a></li>
</ul>
<p>I’d like to know how you validate complex dynamic forms, so please leave your comments here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2009/04/dynamic-form-elements-the-jquery-validation-plugin/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Guest Posts And the_author() In Your WordPress Blog</title>
		<link>http://www.flowdrops.com/blog/2008/08/guest-posts-and-the_author-in-your-wordpress-blog/</link>
		<comments>http://www.flowdrops.com/blog/2008/08/guest-posts-and-the_author-in-your-wordpress-blog/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 13:24:12 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/2008/08/18/guest-posts-and-the_author-in-your-wordpress-blog/</guid>
		<description><![CDATA[As you may have seen I have a guest post on this blog written by Matt from phuketvogue.com. Since I am the only registered writer/author on this site, all posts are marked as &#8216;written by Toxane&#8217; or something similar. I &#8230; <a href="http://www.flowdrops.com/blog/2008/08/guest-posts-and-the_author-in-your-wordpress-blog/">Read post <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As you may have seen I have a guest post on this blog written by <a href="http://whatismatt.com/" target="_blank">Matt</a> from <a href="http://phuketvogue.com/" target="_blank">phuketvogue.com</a>. Since I am the only registered writer/author on this site, all posts are marked as &#8216;written by Toxane&#8217; or something similar. I thought it would be just fair for the guest writer, to mark these posts with the corresponding author name and a link back to the author&#8217;s site.</p>
<p>What I didn&#8217;t want was to have the guest authors as registered WordPress users on my blog, just to keep things simple (and save). I came up with the following solution:</p>
<p>In my theme folder I have my &#8216;functions.php&#8217; file and I added the following code to it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Guest Posts</span>
<span style="color: #000000; font-weight: bold;">function</span> theAuthor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$guestName</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;guestName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$guestLink</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;guestLink&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$guestName</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$guestLink</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><span style="color: #000088;">$guestLink</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; target=&quot;_blank&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$guestName</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;'</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: #b1b100;">echo</span> <span style="color: #000088;">$guestName</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		the_author<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The code checks if the post has a custom field &#8216;guestName&#8217;. If the field is found, the code further checks if there&#8217;s a custom field &#8216;guestLink&#8217;. If that field is found as well, the code returns the name of the guest author as a hyperlink back to the guest authors website. If there&#8217;s no &#8216;guestLink&#8217;, only the guest author&#8217;s name is returned. If both custom fields are missing, the code returns &#8216;the_author()&#8217; which is the registered WordPress user.</p>
<p>Next I replaced all occurences of &#8216;the_author()&#8217; in the theme files with &#8216;theAuthor()&#8217;</p>
<p>To mark any post in your WordPress Blog as a guest post, you just add a custom field &#8216;guestName&#8217; and the name of the guest author as value. If you want the guest author&#8217;s name appears as a hyperlink, just add a custom field &#8216;guestLink&#8217; and the web address of the guest author as value.</p>
<p>That&#8217;s it. Simple and fair for your guest author(s).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2008/08/guest-posts-and-the_author-in-your-wordpress-blog/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>WordPress, My Gravatar and the Mystery Man</title>
		<link>http://www.flowdrops.com/blog/2008/08/wordpress-my-gravatar-and-the-mystery-man/</link>
		<comments>http://www.flowdrops.com/blog/2008/08/wordpress-my-gravatar-and-the-mystery-man/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 05:04:34 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Gravatars]]></category>
		<category><![CDATA[Mystery Man]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=170</guid>
		<description><![CDATA[I just had a problem with my own gravatar not showing up on my own site for the comments I wrote. First I thought that clearing the browser cache would solve everything. I was wrong. After clearing the cache, deleting &#8230; <a href="http://www.flowdrops.com/blog/2008/08/wordpress-my-gravatar-and-the-mystery-man/">Read post <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div id="attachment_174" class="wp-caption alignright" style="width: 106px"><img class="size-full wp-image-174" title="Mystery Man" src="http://www.flowdrops.com/wp-content/uploads/2008/08/mystery-man.jpeg" alt="Mystery Man - the default Gravatar" width="96" height="96" /><p class="wp-caption-text">Mystery Man - the default Gravatar</p></div>
<p>I just had a problem with my own <a href="http://www.gravatar.com/" target="_blank">gravatar</a> not showing up on my own site for the comments I wrote. First I thought that clearing the browser cache would solve everything. I was wrong. After clearing the cache, deleting cookies and checking my gravatar (<a href="http://en.gravatar.com/site/check/" target="_blank">http://en.gravatar.com/site/check/</a>), I was really out of (quick) ideas. Then it suddenly hit me: a few days ago I changed a few things in my Blog&#8217;s user accounts. I added new accounts with different user rights and merged the old accounts with the new ones.</p>
<p>After having a look at WordPress&#8217;s gravatar code (wp-includes/pluggable.php), everything was clear: WordPress actually pulls the user id and gets the email address which is stored in the user account data for this id. This ensures that if a user changes the email address in the user account, it will always pull the new gravatar associated with the new email address. The user id &#8211; for registered users &#8211; is stored in the comments table for each and every comment.</p>
<p>That said, if you change user accounts and a user id changes, you need to run</p>
<pre>UPDATE wp_comments SET user_id = new_user_id WHERE user_id = old_user_id</pre>
<p>otherwise you&#8217;re going to have a lot comments from the mystery man&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2008/08/wordpress-my-gravatar-and-the-mystery-man/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PayPal donation form with CSS and jQuery for WordPress</title>
		<link>http://www.flowdrops.com/blog/2008/08/paypal-donation-form-with-css-and-jquery-for-wordpress/</link>
		<comments>http://www.flowdrops.com/blog/2008/08/paypal-donation-form-with-css-and-jquery-for-wordpress/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 05:00:26 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Donation]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PayPal]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=157</guid>
		<description><![CDATA[Learn how to create a PayPal donation form, beautify it with a little bit CSS and validate the input with jQuery. You can also integrate the form into WordPress as a page template or use it on any other static HTML page. <a href="http://www.flowdrops.com/blog/2008/08/paypal-donation-form-with-css-and-jquery-for-wordpress/">Read post <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Yesterday I got an email from Jamie asking me how I made my <a href="http://www.flowdrops.com/donate/" target="_blank">PayPal donation</a> form. Here&#8217;s how I did it.</p>
<p>First, we need a PayPal form with the donation stuff inside:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;form_paypal&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;https://www.paypal.com/cgi-bin/webscr&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cmd&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;_donations&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;business&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;paypal@email.com&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item_name&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;My Donations Subject&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;no_shipping&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;no_note&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;currency_code&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;USD&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tax&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bn&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;PP-DonationsBF&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>Amount (US$) : <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;amount&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;input_amount&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Donate&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></td></tr></table></div>

<p>More information about the PayPal donation buttons and the form code behind can be found here: <a title="https://www.paypal.com/cgi-bin/webscr?cmd=_pdn_donate_techview_outside" href="https://www.paypal.com/cgi-bin/webscr?cmd=_pdn_donate_techview_outside">https://www.paypal.com/cgi-bin/webscr?cmd=_pdn_donate_techview_outside</a></p>
<p>Next, we need to add some more code to the form where we want to show the various messages displayed by jQuery. These messages are set to be hidden (display:none;):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Donate&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;&amp;nbsp;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;msg_moreamount&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;icon_warning red&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;display:none;&quot;</span>&gt;</span>PayPal takes $0.35 commission for a $1 donation. Please enter at least $1.35 , thank you!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;msg_noamount&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;icon_warning red&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;display:none;&quot;</span>&gt;</span>Please enter the amount you wish to donate and try again.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;msg_activity&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;display:none;&quot;</span>&gt;</span> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/loader.gif&quot;</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;absmiddle&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span>Transferring to PayPal, please wait...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></pre></td></tr></table></div>

<p>The jQuery script which actually checks and validates the form looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// the minimum required value to be entered.</span>
	<span style="color: #006600; font-style: italic;">// in this case PayPal takes $0.35 from a $1</span>
	<span style="color: #006600; font-style: italic;">// donation, hence we ask for at least $1.35</span>
	<span style="color: #003366; font-weight: bold;">var</span> minimum_value <span style="color: #339933;">=</span> <span style="color: #CC0000;">1.35</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// attach this script to the form's submit action</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#form_paypal'</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: #006600; font-style: italic;">// check if there is an amount entered</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#input_amount'</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;">&gt;</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">// is the amount equal to or higher than the minimum_value?</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#input_amount'</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;">&lt;</span> minimum_value<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// need more amount</span>
				<span style="color: #006600; font-style: italic;">// hide messages, show more amount error</span>
				jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#msg_noamount'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#msg_moreamount'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</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: #006600; font-style: italic;">// prevent the form from submitting</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// amount is more than minimum_value</span>
				<span style="color: #006600; font-style: italic;">// hide messages, show activity</span>
				jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#msg_moreamount'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#msg_noamount'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#msg_activity'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</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;">true</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// submit the form</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: #006600; font-style: italic;">// no amount entered at all</span>
			<span style="color: #006600; font-style: italic;">// hide messages, show no amount error</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#msg_moreamount'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#msg_noamount'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</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: #006600; font-style: italic;">// prevent the form from submitting</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: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The code is documented so it should be clear what each block does.</p>
<p>The final step is to add some CSS styling:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.red</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;">#ff0000</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.icon_warning</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #3333ff;">:<span style="color: #993333;">transparent</span> </span>url<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../images/exclamation.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>padding-<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
form<span style="color: #cc00cc;">#form_paypal</span> input <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>border<span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>background<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fefefe</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
form<span style="color: #cc00cc;">#form_paypal</span> input<span style="color: #cc00cc;">#input_amount</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
form<span style="color: #cc00cc;">#form_paypal</span> <span style="color: #6666ff;">.submit</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>border-style<span style="color: #00AA00;">:</span><span style="color: #993333;">outset</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>If you want to integrate this form into your WordPress Blog then this is the way to go:</p>
<p>In your WordPress Theme folder (wp-content/themes/yourtheme/) create a new file named &#8216;donate.php&#8217;. To make the file available as a WordPress page template you&#8217;ll need to add the following code at the top of the file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Template Name: Donate
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>A donation form template for the default theme would look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Template Name: Donate
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;content&quot; class=&quot;narrowcolumn&quot;&gt;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;div class=&quot;post&quot; id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
    &lt;h2&gt;Make A Donation&lt;/h2&gt;
    &lt;p&gt;If you think you have benefited or I have helped you in some way, by using any of my
    WordPress plugins or themes, please consider making a donation. Donations support the
    continued development of my websites and help cover the hosting costs.
    Donations of any size are gratefully accepted. Thank you!&lt;/p&gt;
    &lt;form id=&quot;ppDonate&quot; action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_donations&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;business&quot; value=&quot;paypal@email.com&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;item_name&quot; value=&quot;My Donations Subject&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;no_shipping&quot; value=&quot;0&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;no_note&quot; value=&quot;1&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;USD&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;tax&quot; value=&quot;0&quot;&gt;
      &lt;input type=&quot;hidden&quot; name=&quot;bn&quot; value=&quot;PP-DonationsBF&quot;&gt;
      &lt;label for=&quot;&quot;&gt;Amount (US$) : &lt;/label&gt;
      &lt;input type=&quot;text&quot; name=&quot;amount&quot; id=&quot;ppAmount&quot; width=&quot;10&quot; class=&quot;text&quot; /&gt;
      &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Donate&quot; class=&quot;submit&quot; /&gt;
      &lt;span id=&quot;moreAmount&quot; class=&quot;warningIcon red&quot; style=&quot;display:none;&quot;&gt;PayPal takes $0.35 commission for $1 donation.
      Please enter at least $1.35 , thank you!&lt;/span&gt;
      &lt;span id=&quot;noAmount&quot; class=&quot;warningIcon red&quot; style=&quot;display:none;&quot;&gt;Please enter an amount to donate and try again.&lt;/span&gt;
      &lt;span id=&quot;ppGo&quot; style=&quot;display:none;&quot;&gt;
      &lt;img src=&quot;&amp;lt;?php bloginfo('template_url'); ?&amp;gt;/images/loader.gif&quot; align=&quot;absmiddle&quot; /&gt;Transferring to PayPal, please wait...&lt;/span&gt;
    &lt;/form&gt;
    &lt;p&gt;&lt;small&gt;Info : once you click on 'Donate', you will be transferred to PayPal where you can enter your payment information.&lt;/small&gt;&lt;/p&gt;
  &lt;/div&gt;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> edit_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Edit this entry.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Next you need to create a page in WordPress, call it &#8216;Donate&#8217;, &#8216;Make A Donation&#8217; or whatever you want the page title to be. You can leave the page content empty as we will use our template file. Scroll down to the &#8216;Page Template&#8217; section and select your page template (&#8216;Donate&#8217; in our case). Save &amp; publish the page.</p>
<p><strong>Available Files</strong></p>
<ul>
<li><span class="downloadLink"><a href="http://www.flowdrops.com/downloads/10">Donation Form Example</a></span></li>
<li><span class="downloadLink"><a href="http://www.flowdrops.com/downloads/11">Donation Form &#8211; WordPress Page Template (default theme)</a></span></li>
</ul>
<p>&nbsp;</p>
<p>Hopefully this short tutorial will be of some use for you (if so, don&#8217;t forget to <a href="http://www.flowdrops.com/donate/" target="_blank">donate</a> ;) ) and if you still have some questions feel free to leave a comment below.</p>
<p><strong>Received Donations</strong></p>
<ul>
<li>Sun 8/17/2008, $5.00 &bull; Saarthak, <a href="http://lughole.net/" target="_blank">http://lughole.net/</a></li>
<li>Mon 10/13/2008, $50.00 &bull; Armando, <a href="http://www.criteriondg.info/" target="_blank">http://www.criteriondg.info/</a></li>
<li>Tue 2/17/2009, $2.00 &bull; McDowell Crook</li>
</ul>
<p>Thank You!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2008/08/paypal-donation-form-with-css-and-jquery-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>54</slash:comments>
		</item>
		<item>
		<title>Desktop Blogging Tools Reviewed</title>
		<link>http://www.flowdrops.com/blog/2008/08/desktop-blogging-tools-reviewed/</link>
		<comments>http://www.flowdrops.com/blog/2008/08/desktop-blogging-tools-reviewed/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 07:01:01 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Worth A Read]]></category>
		<category><![CDATA[Blogging]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=148</guid>
		<description><![CDATA[Just a quick post to let you know that Glen over at Smashing Magazine has written a cool review of 15 desktop blogging tools.]]></description>
			<content:encoded><![CDATA[<p>Just a quick post to let you know that Glen over at <a href="http://www.smashingmagazine.com/" target="_blank">Smashing Magazine</a> has written a cool review of <a href="http://www.smashingmagazine.com/2008/08/01/15-desktop-blogging-tools-reviewed/" target="_blank">15 desktop blogging tools</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flowdrops.com/blog/2008/08/desktop-blogging-tools-reviewed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
