<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Swiss WP</title>
	
	<link>http://www.swisswp.com</link>
	<description>High Quality Web Solutions, Specialized On WordPress™</description>
	<lastBuildDate>Sat, 16 Jun 2012 05:40:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/swisswp" /><feedburner:info uri="swisswp" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Multiple column lists navigation using wp_nav_menu</title>
		<link>http://www.swisswp.com/blog/2010/12/multiple-column-lists-navigation-using-wp_nav_menu/</link>
		<comments>http://www.swisswp.com/blog/2010/12/multiple-column-lists-navigation-using-wp_nav_menu/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 21:46:00 +0000</pubDate>
		<dc:creator>Peter Michael</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[walker_nav_menu]]></category>
		<category><![CDATA[wp_nav_menu]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=461</guid>
		<description><![CDATA[Intro Working on a recent project I had to made use of &#8216;multiple column lists&#8217;, based on the article &#8216;CSS Swag: Multi-Column Lists&#8216; at A List Apart. For more control over the items in the list, I wanted to use the WordPress custom menus. This is the final result: The CSS The CSS is pretty ...]]></description>
			<content:encoded><![CDATA[<h3>Intro</h3>
<p>Working on a recent project I had to made use of &#8216;multiple column lists&#8217;, based on the article &#8216;<a href="http://www.alistapart.com/articles/multicolumnlists/">CSS Swag: Multi-Column Lists</a>&#8216; at <a href="http://www.alistapart.com/">A List Apart</a>. For more control over the items in the list, I wanted to use the WordPress custom menus. This is the final result:</p>
<p><img class="alignnone size-full wp-image-464" title="Multiple CSS Column List" src="http://www.swisswp.com/wordpress/wp-content/uploads/2011/08/screen01.jpg" alt="Multiple CSS Column List" width="490" height="222" /></p>
<h3>The CSS</h3>
<p>The CSS is pretty straight forward. You can see a basic example here: <a href="http://www.alistapart.com/d/multicolumnlists/example6.html" target="_blank">http://www.alistapart.com/d/multicolumnlists/example6.html</a></p>
<p>Instead of using a different class for each and every list item, I wanted to use  &#8216;firstcolumn&#8217;, &#8216;secondcolumn&#8217; and so on for the list items and &#8216;colheader&#8217; for the items at the top.</p>
<pre class="brush: css">
/* http://www.alistapart.com/d/multicolumnlists/example6.html */
* html ul li{position:relative;}
ul li{line-height:1.2em;margin:0;padding:0;}
ul li.colheader{margin-top:-104px;} /* I&#039;m using pixels here, but generally it is &#039;list item count&#039; x &#039;line-height&#039; (4*1.2) */
ul li.firstcol{margin-left:0em;}
ul li.secondcol{margin-left:160px;} /* a width + padding */
ul li.thirdcol{margin-left:320px;}
ul li a{display:block;width:145px;height:16px;padding:0 0 0 15px;margin:0 0 10px 0;}
ul li a:hover, ul li.current_page_item a{color:#adadad;}
</pre>
<p>This creates the basic CSS for the list items.</p>
<h3>The PHP code</h3>
<p>The wp_nav_menu function provides filters and an option to provide your own <a href="http://codex.wordpress.org/Function_Reference/Walker_Class" target="_blank">Walker</a> class which we will use here. Basically, all we need to add is a item counter and add additional CSS classes at certain postitions. Based on the original &#8216;Walker_Nav_Menu&#8217; class, not much needs to be added:</p>
<p>First, we need to have a variable &#8216;$item_count&#8217; to keep the list items count:</p>
<pre class="brush: php">
class my_footer_menu_walker extends Walker {
var $item_count = 0;
/**
* @see Walker::$tree_type
* @since 3.0.0
* @var string
*/
var $tree_type = array( &#039;post_type&#039;, &#039;taxonomy&#039;, &#039;custom&#039; );
....
</pre>
<p>Next, we need to modify the function &#8216;start_el&#8217; by adding the previously declared variable and add our custom CSS classes to the generated list items:</p>
<pre class="brush: php">
function start_el(&amp;amp;amp;amp;amp;$output, $item, $depth, $args) {
global $wp_query, $item_count;

$indent = ( $depth ) ? str_repeat( &quot;t&quot;, $depth ) : &#039;&#039;;

$class_names = $value = &#039;&#039;;

$classes = empty( $item-&gt;classes ) ? array() : (array) $item-&gt;classes;
$classes[] = &#039;menu-item-&#039; . $item-&gt;ID;

# START adding column classes
if($item_count &lt;= 3)
{
$classes[] = &#039;firstcol&#039;;
}

if($item_count == 4)
{
$classes[] = &#039;colheader&#039;;
}

if($item_count &gt; 3 &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; $item_count &lt;= 7)
{
$classes[] = &#039;secondcol&#039;;
}

if($item_count == 8)
{
$classes[] = &#039;colheader&#039;;
}

if($item_count &gt; 7 &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; $item_count &lt;= 13)
{
$classes[] = &#039;thirdcol&#039;;
}
# END adding column classes

$class_names = join( &#039; &#039;, apply_filters( &#039;nav_menu_css_class&#039;, array_filter( $classes ), $item ) );
$class_names = &#039; class=&quot;&#039; . esc_attr( $class_names ) . &#039;&quot;&#039;;
....
</pre>
<p>Finally, at the end of the function we need to increase the counter:</p>
<pre class="brush: php">
...
$output .= apply_filters( &#039;walker_nav_menu_start_el&#039;, $item_output, $item, $depth, $args );
$item_count ++;
}
</pre>
<p>The full code:</p>
<pre class="brush: php">
# Custom walker class for the wp_nav_menu
class my_footer_menu_walker extends Walker
{
	var $item_count = 0;
	/**
	* @see Walker::$tree_type
	* @since 3.0.0
	* @var string
	*/
	var $tree_type = array( &#039;post_type&#039;, &#039;taxonomy&#039;, &#039;custom&#039; );

	/**
	* @see Walker::$db_fields
	* @since 3.0.0
	* @todo Decouple this.
	* @var array
	*/
	var $db_fields = array( &#039;parent&#039; =&gt; &#039;menu_item_parent&#039;, &#039;id&#039; =&gt; &#039;db_id&#039; );

	/**
	* @see Walker::start_lvl()
	* @since 3.0.0
	*
	* @param string $output Passed by reference. Used to append additional content.
	* @param int $depth Depth of page. Used for padding.
	*/
	function start_lvl(&amp;$output, $depth) {
		$indent = str_repeat(&quot;t&quot;, $depth);
		$output .= &quot;n$indent&lt;ul class=&quot;sub-menu depth-$depth&quot;&gt;n&quot;;
	}

	/**
	* @see Walker::end_lvl()
	* @since 3.0.0
	*
	* @param string $output Passed by reference. Used to append additional content.
	* @param int $depth Depth of page. Used for padding.
	*/
	function end_lvl(&amp;$output, $depth) {
		$indent = str_repeat(&quot;t&quot;, $depth);
		$output .= &quot;$indent&lt;/ul&gt;n&quot;;
	}

	/**
	* @see Walker::start_el()
	* @since 3.0.0
	*
	* @param string $output Passed by reference. Used to append additional content.
	* @param object $item Menu item data object.
	* @param int $depth Depth of menu item. Used for padding.
	* @param int $current_page Menu item ID.
	* @param object $args
	*/
	function start_el(&amp;$output, $item, $depth, $args) {
		global $wp_query, $item_count;

		$indent = ( $depth ) ? str_repeat( &quot;t&quot;, $depth ) : &#039;&#039;;

		$class_names = $value = &#039;&#039;;

		$classes = empty( $item-&gt;classes ) ? array() : (array) $item-&gt;classes;
		$classes[] = &#039;menu-item-&#039; . $item-&gt;ID;

		# Hack for adding column classes
		if($item_count &lt;= 3)
		{
			$classes[] = &#039;firstcol&#039;;
		}

		if($item_count == 4)
		{
			$classes[] = &#039;colheader&#039;;
		}

		if($item_count &gt; 3 &amp;&amp; $item_count &lt;= 7)
		{
			$classes[] = &#039;secondcol&#039;;
		}

		if($item_count == 8)
		{
			$classes[] = &#039;colheader&#039;;
		}

		if($item_count &gt; 7 &amp;&amp; $item_count &lt;= 13)
		{
			$classes[] = &#039;thirdcol&#039;;
		}

		$class_names = join( &#039; &#039;, apply_filters( &#039;nav_menu_css_class&#039;, array_filter( $classes ), $item ) );
		$class_names = &#039; class=&quot;&#039; . esc_attr( $class_names ) . &#039;&quot;&#039;;

		$id = apply_filters( &#039;nav_menu_item_id&#039;, &#039;menu-item-&#039;. $item-&gt;ID, $item, $args );
		$id = strlen( $id ) ? &#039; id=&quot;&#039; . esc_attr( $id ) . &#039;&quot;&#039; : &#039;&#039;;

		$output .= $indent . &#039;&lt;li&#039; . $id . $value . $class_names .&#039;&gt;&#039;;

		$attributes = ! empty( $item-&gt;attr_title ) ? &#039; title=&quot;&#039; . esc_attr( $item-&gt;attr_title ) .&#039;&quot;&#039; : &#039;&#039;;
		$attributes .= ! empty( $item-&gt;target ) ? &#039; target=&quot;&#039; . esc_attr( $item-&gt;target ) .&#039;&quot;&#039; : &#039;&#039;;
		$attributes .= ! empty( $item-&gt;xfn ) ? &#039; rel=&quot;&#039; . esc_attr( $item-&gt;xfn ) .&#039;&quot;&#039; : &#039;&#039;;
		$attributes .= ! empty( $item-&gt;url ) ? &#039; href=&quot;&#039; . esc_attr( $item-&gt;url ) .&#039;&quot;&#039; : &#039;&#039;;

		# A little hack to disable clicking on links
		$is_clickable = get_post_meta($item-&gt;object_id, &#039;link_disabled&#039;, true);
		$jsarg = ($is_clickable == &#039;1&#039;) ? &#039;onclick=&quot;return false;&quot;&#039; : &#039;&#039;;

		$item_output = $args-&gt;before;
		$item_output .= &#039;&lt;a&#039;. $attributes .&#039; &#039;.$jsarg.&#039;&gt;&#039;;
		$item_output .= $args-&gt;link_before . apply_filters( &#039;the_title&#039;, $item-&gt;title, $item-&gt;ID ) . $args-&gt;link_after;
		$item_output .= &#039;&lt;/a&gt;&#039;;
		$item_output .= $args-&gt;after;

		$output .= apply_filters( &#039;walker_nav_menu_start_el&#039;, $item_output, $item, $depth, $args );

		$item_count ++;
	}

	/**
	* @see Walker::end_el()
	* @since 3.0.0
	*
	* @param string $output Passed by reference. Used to append additional content.
	* @param object $item Page data object. Not used.
	* @param int $depth Depth of page. Not Used.
	*/
	function end_el(&amp;$output, $item, $depth) {
		$output .= &quot;&lt;/li&gt;n&quot;;
	}
}
</pre>
<h3>The Menu</h3>
<p>Left to do is tell the wp_nav_menu to use our custom walker class:</p>
<pre class="brush: php">
wp_nav_menu( array( &#039;container_class&#039; =&gt; &#039;&#039;, &#039;container&#039; =&gt; &#039;&#039;, &#039;theme_location&#039; =&gt; &#039;footer&#039;, &#039;walker&#039; =&gt; new my_footer_menu_walker ) );
</pre>
<p>That&#8217;s it. ;-)</p>
<p>Please leave your comments, I&#8217;d like to know how you modify your menus.</p>
<hr />
<p><small>© 2010 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2010/12/multiple-column-lists-navigation-using-wp_nav_menu/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2010/12/multiple-column-lists-navigation-using-wp_nav_menu/#comments">10 comments</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2010/12/multiple-column-lists-navigation-using-wp_nav_menu/&title=Multiple column lists navigation using wp_nav_menu">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/css/" rel="tag">css</a>, <a href="http://www.swisswp.com/tag/php/" rel="tag">php</a>, <a href="http://www.swisswp.com/tag/walker_nav_menu/" rel="tag">walker_nav_menu</a>, <a href="http://www.swisswp.com/tag/wp_nav_menu/" rel="tag">wp_nav_menu</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.com/blog/2010/12/multiple-column-lists-navigation-using-wp_nav_menu/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>10 Code Snippets For Your WordPress Theme Functions.php File</title>
		<link>http://www.swisswp.com/blog/2010/05/10-code-snippets-for-your-wordpress-theme-functions-php-file/</link>
		<comments>http://www.swisswp.com/blog/2010/05/10-code-snippets-for-your-wordpress-theme-functions-php-file/#comments</comments>
		<pubDate>Sun, 16 May 2010 14:11:18 +0000</pubDate>
		<dc:creator>Peter Michael</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></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 (!empty($_SERVER[&#039;SCRIPT_FILENAME&#039;]) &#38;amp;&#38;amp; &#039;functions.php&#039; == basename($_SERVER[&#039;SCRIPT_FILENAME&#039;])) { die (&#039;He&#039;s dead, Jim!&#039;); } Put this code on the top of ...]]></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>
<h3>1. Prevent Direct File Access</h3>
<pre class="brush: php">
# No direct file load
if (!empty($_SERVER[&#039;SCRIPT_FILENAME&#039;]) &amp;amp;&amp;amp; &#039;functions.php&#039; == basename($_SERVER[&#039;SCRIPT_FILENAME&#039;]))
{
die (&#039;He&#039;s dead, Jim!&#039;);
}
</pre>
<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>
<h3>2. Set Debugging Variables</h3>
<pre class="brush: php">
# Debugging
define( &#039;IS_SITE_DEBUG&#039;, true ); // Really up to you how you use this variable
error_reporting(E_ALL); // Shows ALL PHP errors. Set to 0 on a live site
</pre>
<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>
<h3>3. File Paths</h3>
<pre class="brush: php">
# Template directory, includes Win/XAMPP compatibility
define( &#039;CURRENT_TEMPLATE_DIR&#039;, str_replace( &#039;&#039;, &#039;/&#039;, get_template_directory() ) );
</pre>
<p>I&#8217;m developing on Windows, so I need those backslashes replaced.</p>
<h3>4. Theme Header</h3>
<pre class="brush: php">
# Set up the WordPress theme header
function my_custom_header()
{
# Add a custom Stylesheet
wp_enqueue_style( &#039;yui_reset&#039;, get_bloginfo(&#039;template_url&#039;).&#039;/css/reset-min.css&#039;, &#039;&#039;, &#039;2.7.0&#039;, &#039;screen&#039; );
# Add custom JavaScript
wp_enqueue_script( &#039;js_main&#039;, get_bloginfo(&#039;template_url&#039;).&#039;/js/js_main.js&#039;, array( &#039;jquery&#039;, &#039;jquery-ui-core&#039;, &#039;jquery-ui-tabs&#039; ), &#039;1.0.0&#039; );
}
# Add only if on front end, never on /wp-admin/
if ( ! is_admin() )
{
add_action(&#039;init&#039;, &#039;my_custom_header&#039;);
}
</pre>
<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>
<h3>5. Custom Functions / Template Tags</h3>
<pre class="brush: php">
if (!function_exists(&#039;getAdvertisings&#039;))
{
function getAdvertisings( $limit = 5 )
{
$ads = get_bookmarks( &#039;category_name=advertisings&amp;amp;limit=&#039;.$limit );
return $ads;
}
}
</pre>
<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>
<h3>6. Helpers</h3>
<pre class="brush: php">
function is_even_number(&amp;amp;$i)
{
return ($i % 2) ? true : false;
}
</pre>
<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>
<h3>7. Prevent Access To WP-Admin</h3>
<pre class="brush: php">
# Disable access to wp-admin for Subscribers
if ( is_user_logged_in() &amp;amp;&amp;amp; is_admin() ) {
global $current_user;
get_currentuserinfo();
$user_info = get_userdata($current_user-&gt;ID);
if ( $user_info-&gt;wp_user_level == 0 )
{
header( &#039;Location: &#039;.get_bloginfo(&#039;home&#039;).&#039;/wp-login.php?redirect=&#039;.get_bloginfo(&#039;home&#039;).&#039;/wp-admin/&#039; );
}
}
</pre>
<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>
<h3>8. No External Stuff While Working Locally</h3>
<pre class="brush: php">
function is_live_site()
{
if (isset($_SERVER[&#039;HTTP_HOST&#039;]))
{
$_live_site_name = &quot;tacocode.com&quot;;
$_compare_to = $_SERVER[&#039;HTTP_HOST&#039;];
$pos = strpos($_live_site_name, $_compare_to);
return ($pos !== false) ? true : false;
}
}
</pre>
<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>
<h3>9. Validate Email Address</h3>
<pre class="brush: php">
function is_email_valid($email, $mx_lookup = false)
{
if(eregi(&quot;^([_a-z0-9-]+)(.[_a-z0-9-]+)*@([a-z0-9-]+)(.[a-z0-9-]+)*(.[a-z]{2,4})$&quot;, $email))
{
if($mx_lookup)
{
list($username, $domain) = split(&quot;@&quot;, $email);
return getmxrr($domain, $mxrecords);
}
else
{
return true;
}
}
else
{
return false;
}
}
</pre>
<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>
<h3>10. Shortened URLs</h3>
<pre class="brush: php">
function get_tiny_url( $url )
{
$tiny_url = file_get_contents( &quot;http://tinyurl.com/api-create.php?url=&quot;.$url );
return $tiny_url;
}
</pre>
<p>Very useful if you want to include a shortened URL of your post somewhere.</p>
<h3>Note</h3>
<p>As a best practice always check if the function name is unused by adding:</p>
<pre class="brush: php">if (!function_exists(&#039;your_function_name&#039;))</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>
<hr />
<p><small>© 2010 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2010/05/10-code-snippets-for-your-wordpress-theme-functions-php-file/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2010/05/10-code-snippets-for-your-wordpress-theme-functions-php-file/#comments">10 comments</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2010/05/10-code-snippets-for-your-wordpress-theme-functions-php-file/&title=10 Code Snippets For Your WordPress Theme Functions.php File">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/code/" rel="tag">code</a>, <a href="http://www.swisswp.com/tag/theme/" rel="tag">theme</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.com/blog/2010/05/10-code-snippets-for-your-wordpress-theme-functions-php-file/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Re-numbering With jQuery</title>
		<link>http://www.swisswp.com/blog/2009/08/re-numbering-with-jquery/</link>
		<comments>http://www.swisswp.com/blog/2009/08/re-numbering-with-jquery/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 10:29:13 +0000</pubDate>
		<dc:creator>Peter Michael</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[code]]></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; items in a unordered list: jQuery(document).ready(function() { renumber_featured_nav(); }); function renumber_featured_nav() { var ftabscount = ...]]></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>
<pre class="brush: js">
jQuery(document).ready(function()
{
    renumber_featured_nav();
});

function renumber_featured_nav()
{
    var ftabscount = 1;
    jQuery(&quot;li.ftab a span&quot;).each(function()
    {
        jQuery(this).html(ftabscount);
        ftabscount++;
    });
}
</pre>
<hr />
<p><small>© 2009 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2009/08/re-numbering-with-jquery/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2009/08/re-numbering-with-jquery/#comments">No comment</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2009/08/re-numbering-with-jquery/&title=Re-numbering With jQuery">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/code/" rel="tag">code</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.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.swisswp.com/blog/2009/08/tip-exclude-categories-from-archive-in-wordpress/</link>
		<comments>http://www.swisswp.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>Peter Michael</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></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: # Exclude categories &#124; archive.php if ( is_home() &#124;&#124; is_category(&#039;one&#039;) &#124;&#124; is_category(&#039;two&#039;) ) { $current_cat = get_query_var( &#039;cat&#039; ); ...]]></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>
<pre class="brush: php">
# Exclude categories | archive.php
if ( is_home() || is_category(&#039;one&#039;) || is_category(&#039;two&#039;) )
{
    $current_cat = get_query_var( &#039;cat&#039; );
    $exclude_cat = 3;
    $current_page = ( get_query_var( &#039;paged&#039; ) ) ? get_query_var( &#039;paged&#039; ) : 1;
    query_posts(&quot;cat=$current_cat,-$exclude_cat&amp;paged=$current_page&quot;);
}
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
</pre>
<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>
<pre class="brush: php">
# Exclude categories | functions.php
function fd_remove_cat( $nada )
{
  global $wp_query;
  if ( is_home() || is_category(&#039;one&#039;) || is_category(&#039;two&#039;) )
  {
     $wp_query-&gt;query_vars[&#039;cat&#039;] = &#039;-3&#039;;
  }
}
add_action(&#039;pre_get_posts&#039;, &#039;fd_remove_cat&#039; );
</pre>
<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>
<pre class="brush: php">
# Exclude categories | archive.php
if ( is_category(&#039;one&#039;) || is_category(&#039;two&#039;) )
{
    global $wpdb;
    $paged = ( get_query_var( &#039;paged&#039; ) ) ? get_query_var( &#039;paged&#039; ) : 1;
    query_posts(
        array_merge(
            array
            (
                &#039;category__in&#039; =&gt; array($cat),
                &#039;category__not_in&#039; =&gt; array(3,4),
                &#039;paged&#039; =&gt; $paged
            ), $wp_query-&gt;query
        )
    );
}
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
</pre>
<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>
<hr />
<p><small>© 2009 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2009/08/tip-exclude-categories-from-archive-in-wordpress/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2009/08/tip-exclude-categories-from-archive-in-wordpress/#comments">13 comments</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2009/08/tip-exclude-categories-from-archive-in-wordpress/&title=Tip: Exclude Categories From Archive In WordPress">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/code/" rel="tag">code</a>, <a href="http://www.swisswp.com/tag/custom_query/" rel="tag">custom_query</a>, <a href="http://www.swisswp.com/tag/php/" rel="tag">php</a>, <a href="http://www.swisswp.com/tag/query_posts/" rel="tag">query_posts</a>, <a href="http://www.swisswp.com/tag/theme/" rel="tag">theme</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.com/blog/2009/08/tip-exclude-categories-from-archive-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Include WordPress Author Biographical Info In Posts</title>
		<link>http://www.swisswp.com/blog/2009/07/include-wordpress-author-biographical-info-in-posts/</link>
		<comments>http://www.swisswp.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>Peter Michael</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[theme]]></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. © 2009 Swiss WP &#124; Permalink &#124; No comment &#124; Add to del.icio.us Post tags: theme, themes]]></description>
			<content:encoded><![CDATA[<p>In addition to <a href="http://www.swisswp.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>
<hr />
<p><small>© 2009 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2009/07/include-wordpress-author-biographical-info-in-posts/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2009/07/include-wordpress-author-biographical-info-in-posts/#comments">No comment</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2009/07/include-wordpress-author-biographical-info-in-posts/&title=Include WordPress Author Biographical Info In Posts">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/theme/" rel="tag">theme</a>, <a href="http://www.swisswp.com/tag/themes/" rel="tag">themes</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.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.swisswp.com/blog/2009/04/dynamic-form-elements-the-jquery-validation-plugin/</link>
		<comments>http://www.swisswp.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>Peter Michael</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[form]]></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 any code on this included. A few searches on in the WWW didn’t bring the ...]]></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. 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>
<pre class="brush: js">
jQuery( jQuery(&quot;input[name=&#039;howhelp&#039;]&quot;) ).change( function()
{
  if ( jQuery(&quot;input[name=&#039;howhelp&#039;]:checked&quot; ).val() == &quot;help&quot; )
  {
    jQuery(&quot;#whathelp&quot;).rules(&quot;add&quot;, &quot;required&quot;);
    jQuery(&quot;#problems&quot;).show();
  }
  else
  {
    jQuery(&quot;#whathelp&quot;).rules(&quot;remove&quot;, &quot;required&quot;);
    jQuery(&quot;#problems&quot;).hide();
  }
});
</pre>
<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://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>
<hr />
<p><small>© 2009 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2009/04/dynamic-form-elements-the-jquery-validation-plugin/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2009/04/dynamic-form-elements-the-jquery-validation-plugin/#comments">11 comments</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2009/04/dynamic-form-elements-the-jquery-validation-plugin/&title=Dynamic form elements &#038; the jQuery validation plugin">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/dynamic/" rel="tag">dynamic</a>, <a href="http://www.swisswp.com/tag/form/" rel="tag">form</a>, <a href="http://www.swisswp.com/tag/validation/" rel="tag">validation</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.com/blog/2009/04/dynamic-form-elements-the-jquery-validation-plugin/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Guest Posts And the_author() In Your WordPress Blog</title>
		<link>http://www.swisswp.com/blog/2008/08/guest-posts-and-the_author-in-your-wordpress-blog/</link>
		<comments>http://www.swisswp.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>Peter Michael</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[themes]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/2008/08/18/guest-posts-and-the_author-in-your-wordpress-blog/</guid>
		<description><![CDATA[This post is outdated: I have converted this into a plugin &#8594; more info &#38; download 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. ...]]></description>
			<content:encoded><![CDATA[<div class="info_box"><strong>This post is outdated:</strong><br />
I have converted this into a plugin &rarr; <a href="/code/wordpress/plugin/ptm-guest-author/">more info &amp; download </a></div>
<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>
<pre class="brush: php">
// Guest Posts
function theAuthor()
{
	$guestName = get_post_custom_values(&quot;guestName&quot;);
	$guestLink = get_post_custom_values(&quot;guestLink&quot;);

	if ($guestName)
	{
		if ($guestLink)
		{
			echo &#039;&lt;a href=&quot;&#039;.$guestLink[0].&#039;&quot; target=&quot;_blank&quot;&gt;&#039;.$guestName[0].&#039;&lt;/a&gt;&#039;;
		}
		else
		{
			echo $guestName[0];
		}
	}
	else
	{
		the_author();
	}
}
</pre>
<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>
<hr />
<p><small>© 2008 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2008/08/guest-posts-and-the_author-in-your-wordpress-blog/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2008/08/guest-posts-and-the_author-in-your-wordpress-blog/#comments">18 comments</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2008/08/guest-posts-and-the_author-in-your-wordpress-blog/&title=Guest Posts And the_author() In Your WordPress Blog">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/code/" rel="tag">code</a>, <a href="http://www.swisswp.com/tag/theme/" rel="tag">theme</a>, <a href="http://www.swisswp.com/tag/themes/" rel="tag">themes</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.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.swisswp.com/blog/2008/08/wordpress-my-gravatar-and-the-mystery-man/</link>
		<comments>http://www.swisswp.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>Peter Michael</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[gravatar]]></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 cookies and checking my gravatar (http://en.gravatar.com/site/check/), I was really out of (quick) ideas. Then it ...]]></description>
			<content:encoded><![CDATA[<div id="attachment_474" class="wp-caption alignright" style="width: 106px"><img class="size-full wp-image-474 " title="Mystery Man" src="http://www.swisswp.com/wordpress/wp-content/uploads/2011/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>
<hr />
<p><small>© 2008 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2008/08/wordpress-my-gravatar-and-the-mystery-man/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2008/08/wordpress-my-gravatar-and-the-mystery-man/#comments">4 comments</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2008/08/wordpress-my-gravatar-and-the-mystery-man/&title=WordPress, My Gravatar and the Mystery Man">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/gravatar/" rel="tag">gravatar</a>, <a href="http://www.swisswp.com/tag/mystery-man/" rel="tag">mystery man</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.com/blog/2008/08/wordpress-my-gravatar-and-the-mystery-man/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PayPal donation form with CSS and jQuery for WordPress</title>
		<link>http://www.swisswp.com/blog/2008/08/paypal-donation-form-with-css-and-jquery-for-wordpress/</link>
		<comments>http://www.swisswp.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>Peter Michael</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[donation]]></category>
		<category><![CDATA[form]]></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.]]></description>
			<content:encoded><![CDATA[<p>Yesterday I got an email from Jamie asking me how I made my <a href="http://tacocode.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>
<pre class="brush: html">
&lt;form id=&quot;form_paypal&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;p&#97;y&#112;al&#64;&#101;&#109;&#97;&#105;l&#46;co&#109;&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;input_amount&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;/form&gt;
</pre>
<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>
<pre class="brush: html">
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Donate&quot; class=&quot;submit&quot; /&gt;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp;
&lt;span id=&quot;msg_moreamount&quot; class=&quot;icon_warning red&quot; style=&quot;display:none;&quot;&gt;PayPal takes $0.35 commission for a $1 donation. Please enter at least $1.35 , thank you!&lt;/span&gt;
&lt;span id=&quot;msg_noamount&quot; class=&quot;icon_warning red&quot; style=&quot;display:none;&quot;&gt;Please enter the amount you wish to donate and try again.&lt;/span&gt;
&lt;span id=&quot;msg_activity&quot; style=&quot;display:none;&quot;&gt; &lt;img src=&quot;images/loader.gif&quot; align=&quot;absmiddle&quot; /&gt;&amp;amp;amp;nbsp;Transferring to PayPal, please wait...&lt;/span&gt;
</pre>
<p>The jQuery script which actually checks and validates the form looks like this:</p>
<pre class="brush: js">
jQuery(document).ready(function()
{
	// the minimum required value to be entered.
	// in this case PayPal takes $0.35 from a $1
	// donation, hence we ask for at least $1.35
	var minimum_value = 1.35;

	// attach this script to the form&#039;s submit action
	jQuery(&#039;#form_paypal&#039;).submit(function()
	{
		// check if there is an amount entered
		if (jQuery(&#039;#input_amount&#039;).val() &gt; null)
		{
			// is the amount equal to or higher than the minimum_value?
			if (jQuery(&#039;#input_amount&#039;).val() &lt; minimum_value)
			{
				// need more amount
				// hide messages, show more amount error
				jQuery(&#039;#msg_noamount&#039;).hide();
				jQuery(&#039;#msg_moreamount&#039;).fadeIn();
				return false; // prevent the form from submitting
			}
			else
			{
				// amount is more than minimum_value
				// hide messages, show activity
				jQuery(&#039;#msg_moreamount&#039;).hide();
				jQuery(&#039;#msg_noamount&#039;).hide();
				jQuery(&#039;#msg_activity&#039;).fadeIn();
				return true; // submit the form
			}
		}
		else
		{
			// no amount entered at all
			// hide messages, show no amount error
			jQuery(&#039;#msg_moreamount&#039;).hide();
			jQuery(&#039;#msg_noamount&#039;).fadeIn();
			return false; // prevent the form from submitting
		}
	});
});
</pre>
<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>
<pre class="brush: css">
.red {color:#ff0000;}
.icon_warning {background:transparent url(../images/exclamation.png) left no-repeat;padding:4px;padding-left:20px;}
form#form_paypal input {padding:3px;border:1px solid #ddd;background:#fefefe;}
form#form_paypal input#input_amount {width:50px;}
form#form_paypal .submit {cursor:pointer;border-style:outset;}
</pre>
<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>
<pre class="brush: php">
&lt;?php
/*
Template Name: Donate
*/
?&gt;
</pre>
<p>A donation form template for the default theme would look like this:</p>
<pre class="brush: php">
&lt;?php
/*
Template Name: Donate
*/
?&gt;
&lt;?php get_header(); ?&gt;
&lt;div id=&quot;content&quot; class=&quot;narrowcolumn&quot;&gt;
  &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
  &lt;div class=&quot;post&quot; id=&quot;post-&lt;?php the_ID(); ?&gt;&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;&#112;&#97;&#121;p&#97;l&#64;email.c&#111;m&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;&lt;?php bloginfo(&#039;template_url&#039;); ?&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 &#039;Donate&#039;, you will be transferred to PayPal where you can enter your payment information.&lt;/small&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;?php endwhile; endif; ?&gt;
  &lt;?php edit_post_link(&#039;Edit this entry.&#039;, &#039;&lt;p&gt;&#039;, &#039;&lt;/p&gt;&#039;); ?&gt;
&lt;/div&gt;
&lt;?php get_sidebar(); ?&gt;
&lt;?php get_footer(); ?&gt;
</pre>
<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>Hopefully this short tutorial will be of some use for you (if so, don&#8217;t forget to <a href="http://tacocode.com/donate/" target="_blank">donate</a> ;) ) and if you still have some questions feel free to leave a comment below.</p>
<hr />
<p><small>© 2008 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2008/08/paypal-donation-form-with-css-and-jquery-for-wordpress/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2008/08/paypal-donation-form-with-css-and-jquery-for-wordpress/#comments">62 comments</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2008/08/paypal-donation-form-with-css-and-jquery-for-wordpress/&title=PayPal donation form with CSS and jQuery for WordPress">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/code/" rel="tag">code</a>, <a href="http://www.swisswp.com/tag/donation/" rel="tag">donation</a>, <a href="http://www.swisswp.com/tag/form/" rel="tag">form</a>, <a href="http://www.swisswp.com/tag/paypal/" rel="tag">paypal</a>, <a href="http://www.swisswp.com/tag/tutorial/" rel="tag">tutorial</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.com/blog/2008/08/paypal-donation-form-with-css-and-jquery-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>62</slash:comments>
		</item>
		<item>
		<title>WordPress Themes and the functions.php file</title>
		<link>http://www.swisswp.com/blog/2008/07/wordpress-themes-functions-php/</link>
		<comments>http://www.swisswp.com/blog/2008/07/wordpress-themes-functions-php/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 09:04:35 +0000</pubDate>
		<dc:creator>Peter Michael</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[themes]]></category>

		<guid isPermaLink="false">http://www.flowdrops.com/?p=109</guid>
		<description><![CDATA[Loads of good free WordPress Themes are out there. And the most of them don&#8217;t make use (or at least no good use) of the &#8216;functions.php&#8216; file. This is how the WordPress Codex describes the file: A theme can optionally use a functions file, which resides in the theme subdirectory and is named functions.php. This ...]]></description>
			<content:encoded><![CDATA[<p>Loads of good free WordPress Themes are out there. And the most of them don&#8217;t make use (or at least no good use) of the &#8216;<a href="http://codex.wordpress.org/Theme_Development#Functions_File" target="_blank">functions.php</a>&#8216; file. This is how the WordPress Codex describes the file:</p>
<blockquote><p>A theme can optionally use a functions file, which resides in the theme subdirectory and is named functions.php. This file basically acts like a <a href="http://codex.wordpress.org/Plugins" target="_blank">plugin</a>, and if it is present in the theme you are using, it is automatically loaded during WordPress initialization (both for admin pages and external pages). Suggested uses for this file:</p>
<p>* Define functions used in several template files of your theme<br />
* Set up an admin screen, giving users options for colors, styles, and other aspects of your theme</p>
<p>The &#8220;Default&#8221; WordPress theme contains a functions.php file that defines functions and an admin screen, so you might want to use it as a model. Since functions.php basically functions as a plugin, the <a href="http://codex.wordpress.org/Function_Reference" target="_blank">Function_Reference</a> list is the best place to go for more information on what you can do with this file.</p></blockquote>
<p>Ok, there&#8217;s a load stuff you can read into about the WordPress functions, but not much is written about this mysterious file or exactly how to use it. Here&#8217;s some info:</p>
<p>Open the functions.php file in your theme folder (create the file if it&#8217;s not there). Add a function to it between &lt;?php and ?&gt; :</p>
<pre class="brush: php">
// Function example. Returns the actual date
function show_date() {
    echo date(&#039;Y-m-d&#039;);
}
</pre>
<p>To use the function in your theme, place this code somewhere (i.e. page.php) inside :</p>
<pre class="brush: php">
&lt;?php show_date(); ?&gt;
</pre>
<p>The date should be shown on your page where you inserted the code. Pretty easy, huh. More? Read on&#8230;</p>
<p><strong>Including stuff in the template header</strong></p>
<p>For my part I always need to load some stuff in the header, sometimes under certain conditions:</p>
<pre class="brush: php">
if (! is_admin() ) { // If we are not in the admin, load stuff
    add_action(&#039;init&#039;, &#039;load_my_script&#039;); // on initialization, execute the function load_my_scripts
    add_action(&#039;wp_head&#039;, &#039;load_my_css&#039;);
}

function load_my_script() {
    // load myscript.js version 1.0, which is dependent on &#039;jquery&#039; and refer to it as &#039;MyScript&#039;
    wp_enqueue_script(&#039;MyScript&#039;, get_template_directory_uri().&#039;/js/myscript.js&#039;, array(&#039;jquery&#039;), &#039;1.0&#039;);
}

function load_my_css() {
    // load myscript.js version 1.0, which is dependent on &#039;jquery&#039; and refer to it as &#039;MyScript&#039;
    echo &#039;&lt;link rel=&quot;stylesheet&quot; href=&quot;&#039; . bloginfo(&#039;template_url&#039;) . &#039;/css/style.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;&#039;.&quot;n&quot;;
}
</pre>
<p>You can check for certain conditions i.e. is_page(), is_home() and so on and add stuff to the header respectively. It makes more sense and saves you bandwidth if you load your JavaScript library which checks the contact form fields for errors only on the page on which the form appears.</p>
<p><strong>Adding custom stuff</strong></p>
<p>Personally I don&#8217;t like it when I work on a theme and while testing the theme locally, it needs to load stuff from the internet like the Google analytics code, sponsor banners and other things. I like it quick. The following code is a simple solution. If the page loads local, don&#8217;t load external stuff, if it&#8217;s on the server in the internet, then load everything. Sometimes, this speeds up things drastically.</p>
<p>In the functions.php add:</p>
<pre class="brush: php">
// Function to stop external things from being loaded while on localhost
function is_local() {
  $is_devbox = false;
  $this_host = gethostbyaddr($_SERVER[&#039;REMOTE_ADDR&#039;]);
  $this_host == &#039;localhost&#039; ? $is_devbox = true : $is_devbox = false;
  return $is_devbox;
}
</pre>
<p>and in the template add:</p>
<pre class="brush: php">
&lt;?php if(! isLocal() ) { ?&gt;
// Add all your stuff here you don&#039;t want to load while on localhost i.e.
// your google analytics code.
&lt;?php } ?&gt;
</pre>
<p><strong>Query the WordPress Database</strong></p>
<p>There&#8217;s a widget for the recent posts. What if we don&#8217;t want to use widgets in our sidebar? We create the function:</p>
<pre class="brush: php">
function get_recent_posts($number) {
// code taken and stripped from wp-includes/widgets.php
if ( !$number || $number &lt;= 5 )
	$number = 5;
else if ( $number &lt; 1 )
	$number = 1;
else if ( $number &gt; 15 )
	$number = 15;
else
	$number = $number;

$q = new WP_Query(array(&#039;showposts&#039; =&gt; $number, &#039;what_to_show&#039; =&gt; &#039;posts&#039;, &#039;post_status&#039; =&gt; &#039;publish&#039;));
if ($q-&gt;have_posts()) :
?&gt;
&lt;ul&gt;
&lt;?php  while ($r-&gt;have_posts()) : $r-&gt;the_post(); ?&gt;
&lt;li&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;&lt;?php if ( get_the_title() ) the_title(); else the_ID(); ?&gt; &lt;/a&gt;&lt;/li&gt;
&lt;?php endwhile; ?&gt;
&lt;/ul&gt;
&lt;?php
wp_reset_query();  // Restore global post data stomped by the_post().
endif;
}
</pre>
<p>Place the following code in the template where you want to show the links to your latest posts:</p>
<pre class="brush: php">
&lt;?php get_recent_posts(8); // latest 8 posts ?&gt;
</pre>
<p>Or you could include a RSS Feed:</p>
<pre class="brush: php">
// Retrieving a RSS feed
function getRSS($uri) {
// http://codex.wordpress.org/Function_Reference/get_rss
$xAbspath = str_replace(&quot;&quot;,&quot;/&quot;,ABSPATH);  // Win/XAMPP compatibility
require_once($xAbspath.&#039;/wp-includes/rss-functions.php&#039;);
echo &#039;&lt;ul&gt;&#039;;
get_rss($uri);
echo &#039;&lt;/ul&gt;&#039;;
}
</pre>
<p>And on your page:</p>
<pre class="brush: php">
&lt;?php getRSS(&#039;http://www.swisswp.com/feed&#039;) ?&gt;
</pre>
<p>There&#8217;s really a lot of functionality you can add to your WordPress theme just by adding php functions to the functions.php file. A good start is the functions.php in the &#8216;default&#8217; theme folder. It shows also how you can add a theme admin page. Go, modify your theme and add some functionality. But keep in mind: less is often more.</p>
<p>&nbsp;</p>
<hr />
<p><small>© 2008 <a href="http://www.swisswp.com">Swiss WP</a> |
<a href="http://www.swisswp.com/blog/2008/07/wordpress-themes-functions-php/">Permalink</a> |
<a href="http://www.swisswp.com/blog/2008/07/wordpress-themes-functions-php/#comments">One comment</a> |
Add to <a href="http://del.icio.us/post?url=http://www.swisswp.com/blog/2008/07/wordpress-themes-functions-php/&title=WordPress Themes and the functions.php file">del.icio.us</a>
<br/>
Post tags: <a href="http://www.swisswp.com/tag/code/" rel="tag">code</a>, <a href="http://www.swisswp.com/tag/php/" rel="tag">php</a>, <a href="http://www.swisswp.com/tag/theme/" rel="tag">theme</a>, <a href="http://www.swisswp.com/tag/themes/" rel="tag">themes</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.swisswp.com/blog/2008/07/wordpress-themes-functions-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 13/17 queries in 0.007 seconds using disk: basic

Served from: www.swisswp.com @ 2012-06-16 12:40:14 -->
