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

<channel>
	<title>Curtis Henson &#187; Code</title>
	<atom:link href="http://curtishenson.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://curtishenson.com</link>
	<description>Freelance Web Designer and Wordpress Guru</description>
	<lastBuildDate>Wed, 21 Jul 2010 15:53:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>WordPress Custom Post Type and Meta Boxes Example</title>
		<link>http://curtishenson.com/wordpress-custom-post-types-and-meta-boxes-example/</link>
		<comments>http://curtishenson.com/wordpress-custom-post-types-and-meta-boxes-example/#comments</comments>
		<pubDate>Sat, 01 May 2010 00:00:27 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=920</guid>
		<description><![CDATA[WordPress 3.0 is coming soon and one of the biggest new features is the ability to add custom post types. Making these custom post types is pretty easy, here is a simple but complete example of creating a link type custom post.]]></description>
			<content:encoded><![CDATA[<p>WordPress 3.0 is coming soon and one of the biggest new features is the ability to add custom post types. Making these custom post types is pretty easy, below is a simple but complete example of creating a link type custom post.</p>
<h3>Register the Custom Post</h3>
<p>The first thing you see here is the <code>register_post_type</code> function which starts everything. You can read about this on the <a href="http://codex.wordpress.org/Function_Reference/register_post_type">codex page</a> or <a href="http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress">Justin Tadlock&#8217;s post</a>. These two pages should get you up to speed fast.</p>
<h3>Actions and Filters</h3>
<p>The next bit of code are all the callbacks. The first two deal with adding the meta box and saving it. The next two change the columns in the WordPress admin when viewing a list of the custom posts. The last is for using custom template names.</p>
<h4>The Meta Box</h4>
<p>The first two functions <code>link_url_meta_box()</code> and <code>save_post_data()</code> deal with the added meta box. I&#8217;ve kept things simple here so it should be easy to follow what&#8217;s happening.</p>
<h4>Custom Columns</h4>
<p>When looking through the list of your custom post you&#8217;ll probably want to display custom columns so it&#8217;s easier to find what you want. The <code>nav_columns</code> and <code>custom_nav_columns</code> control this: <code>nav_columns</code> sets everything up, and <code>custom_nav_columns</code> determines what will be listed there.</p>
<h4>Custom Template Names</h4>
<p>WordPress by default will use &#8220;<em>single-link.php</em>&#8221; for our template name since we named the custom post type &#8220;<em>link</em>&#8220;. But if you wanted to use a different template name for instance &#8220;<em>foorbarlink.php</em>&#8221; you can change it using this part of the code. If you&#8217;re happy with WordPress&#8217; default naming you can exclude this completely.<br />
<em><br />
Below is the function for a link type post, one that you might use in a tumble log. It&#8217;s a basic example of how to use the Custom Post Type feature in WordPress 3.0+</em><br />
<script src="http://gist.github.com/385765.js?file=custom_post_types.php"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/wordpress-custom-post-types-and-meta-boxes-example/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Creating a Chart on Your WordPress Archives Page</title>
		<link>http://curtishenson.com/creating-a-chart-on-your-wordpress-archives-page/</link>
		<comments>http://curtishenson.com/creating-a-chart-on-your-wordpress-archives-page/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 16:00:29 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=638</guid>
		<description><![CDATA[One part of WordPress that I've never been overly impressed with is archives. This isn't so much a WordPress problem as it an archive problem, archives are inherently boring. As a result of this revelation I've spent some time thinking up new ways to present the information. My latest idea was adding charts to represent some of the data from the archives.]]></description>
			<content:encoded><![CDATA[<p>One part of WordPress that I&#8217;ve never been overly impressed with is archives. This isn&#8217;t so much a WordPress problem as it an archive problem, archives are inherently boring. As a result of this revelation I&#8217;ve spent some time thinking up new ways to present the information. My latest idea was adding charts to represent some of the data from the archives. This is a fairly simple function to output the info and style it as a chart. </p>
<p><em>If you want to use a flash or javascript chart, scroll to the bottom for a different function.</em></p>
<p><img src="http://curtishenson.com/wp-content/uploads/2009/07/chart.jpg" alt="chart" title="chart" class="alignnone size-full wp-image-650" /></p>
<h3>The Chart</h3>
<p>After looking for a lightweight flash or javascript charting solution, I decided for an archives page just plain CSS charts would be the way to go at first. So the output we are going for is something like this:</p>
<pre name="code" class="html">
&lt;dl class=&quot;barGraph 2008&quot;&gt;
	&lt;dt style=&quot;&quot; class=&quot;label&quot;&gt;&lt;a href=&quot;&quot;&gt;Jun&lt;/a&gt;&lt;/dt&gt;
	&lt;dd title=&quot;Jun&quot; style=&quot;height: 200px;&quot; class=&quot;bar Jun&quot;&gt;6&lt;/dd&gt;

	&lt;dt style=&quot;left: 55px;&quot; class=&quot;label&quot;&gt;&lt;a href=&quot;&quot;&gt;Jul&lt;/a&gt;&lt;/dt&gt;
	&lt;dd title=&quot;Jul&quot; style=&quot;height: 66.6667px; left: 55px;&quot; class=&quot;bar Jul&quot;&gt;2&lt;/dd&gt;

	&lt;dt style=&quot;left: 110px;&quot; class=&quot;label&quot;&gt;&lt;a href=&quot;&quot;&gt;Aug&lt;/a&gt;&lt;/dt&gt;
	&lt;dd title=&quot;Aug&quot; style=&quot;height: 100px; left: 110px;&quot; class=&quot;bar Aug&quot;&gt;3&lt;/dd&gt;

	&lt;dt style=&quot;left: 165px;&quot; class=&quot;label&quot;&gt;&lt;a href=&quot;&quot;&gt;Sep&lt;/a&gt;&lt;/dt&gt;
	&lt;dd title=&quot;Sep&quot; style=&quot;height: 133.333px; left: 165px;&quot; class=&quot;bar Sep&quot;&gt;4&lt;/dd&gt;

	&lt;dt style=&quot;left: 220px;&quot; class=&quot;label&quot;&gt;&lt;a href=&quot;&quot;&gt;Oct&lt;/a&gt;&lt;/dt&gt;
	&lt;dd title=&quot;Oct&quot; style=&quot;height: 166.667px; left: 220px;&quot; class=&quot;bar Oct&quot;&gt;5&lt;/dd&gt;

	&lt;dt style=&quot;left: 275px;&quot; class=&quot;label&quot;&gt;&lt;a href=&quot;&quot;&gt;Nov&lt;/a&gt;&lt;/dt&gt;
	&lt;dd title=&quot;Nov&quot; style=&quot;height: 100px; left: 275px;&quot; class=&quot;bar Nov&quot;&gt;3&lt;/dd&gt;

	&lt;dt style=&quot;left: 330px;&quot; class=&quot;label&quot;&gt;&lt;a href=&quot;&quot;&gt;Dec&lt;/a&gt;&lt;/dt&gt;
	&lt;dd title=&quot;Dec&quot; style=&quot;height: 66.6667px; left: 330px;&quot; class=&quot;bar Dec&quot;&gt;2&lt;/dd&gt;
&lt;/dl&gt;
</pre>
<h3>The Code</h3>
<p>The code in the function is essentially a Frankenstein of the wp_get_archives function from the WordPress core, and this <a href="http://www.terrill.ca/design/vertical_bar_graphs/">tutorial on creating vertical bar graphs</a>. It pulls the year, month and number of posts out of the database, then formats them into a list suitable for styling into a CSS chart.</p>
<pre name="code" class="php">
&lt;?php
function ch_archive_graph($args = ''){
	global $wpdb, $wp_locale;

	//template tag defaults
	$defaults = array(
		'graphYear' =&gt; '2007',
		'limit' =&gt; '13',
		'graphHeight' =&gt; '200',
		'xIncrement' =&gt; '55'
	);

	$maxHeight = 1;
	$scale = 1;

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	if ( '' != $limit ) {
		$limit = absint($limit + 1);
		$limit = ' LIMIT '.$limit;
	}

	$where = apply_filters('getarchives_where', &quot;WHERE post_type = 'post' AND post_status = 'publish'&quot;, $r );

	$query = &quot;SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb-&gt;posts $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit&quot;;
	$key = md5($query);
	$cache = wp_cache_get( 'ch_archive_graph' , 'general');

	$output = '&lt;dl class=&quot;barGraph '.$graphYear.'&quot;&gt;';

	if ( !isset( $cache[ $key ] ) ) {
		$arcresults = $wpdb-&gt;get_results($query);
		$cache[ $key ] = $arcresults;
		wp_cache_add( 'ch_archive_graph', $cache, 'general' );
	} else {
		$arcresults = $cache[ $key ];
	}
	if ( $arcresults ) {

		//Loop through to find the highest number of posts
		foreach ( (array) $arcresults as $arcresult ) {
			//number of posts in a month
			$total = $arcresult-&gt;posts;
			if($maxHeight &lt; $total) $maxHeight = $total;
		}

		//Reverse the months
		$arcresults = array_reverse($arcresults);
		foreach ( (array) $arcresults as $arcresult ) {
			//Limit to one year
			if($arcresult-&gt;year == $graphYear){
				//Get month name, then appreviate, delete the second line if you want full month names
				$month = sprintf(__('%1$s'), $wp_locale-&gt;get_month($arcresult-&gt;month));
				$month = sprintf(__('%1$s'), $wp_locale-&gt;get_month_abbrev($month));
				//Get archive link
				$url = get_month_link( $arcresult-&gt;year, $arcresult-&gt;month );
				//Number of posts in the month
				$num_posts = $arcresult-&gt;posts;

				//Determine the scale and the height of the bar
				$scale = $graphHeight / $maxHeight;
				$height = ($arcresult-&gt;posts * $scale);

				//Put it all together
				$output .= &quot;&lt;dt class='label' style='left: &quot;.$xOffset.&quot;px;'&gt;&lt;a href=&quot;.$url.&quot;&gt;&quot;.$month.&quot;&lt;/a&gt;&lt;/dt&gt;&quot;;
				$output .= &quot;&lt;dd class='bar &quot;.$month.&quot;' style='height: &quot;.$height.&quot;px; left: &quot;.$xOffset.&quot;px;' title=&quot;.$month.&quot;&gt;&quot;.$num_posts.&quot;&lt;/dd&gt;&quot;;

				//Increase the offset for the next bar
				$xOffset = $xOffset + $xIncrement;
			}
		}
	}	

	$output .= &quot;&lt;/dl&gt;&quot;;
	echo $output;

}
</pre>
<h3>Styling the Chart with CSS </h3>
<p>Styling the chart is made easier by the definition list.</p>
<pre name="code" class="css">
.barGraph {
	height: 200px;
	margin: 0;
	padding: 0;
	position: relative;
	}

.barGraph dt {
	bottom: 0;
	list-style:none;
	margin: 0;
	padding: 0;
	position: absolute;
	text-align: center;
	width: 54px;
	}

.barGraph dd {
	border: 1px solid #005559;
	bottom: 0;
	list-style:none;
	margin: 0 0 1.5em 0;
	padding: 0;
	position: absolute;
	text-align: center;
	width: 50px;
	background-color: #00868B;
	border-right: 5px solid #005559;
	color: #fff;
	font-weight: bold;
	}

	.barGraph dd:hover {
		border: 1px solid #FA8000;
		background-color: #F5BA52;
		border-right: 5px solid #FA8000;
		color: #000;
		}
</pre>
<h3>How to use the Graph</h3>
<p>The function works just like any other template tag. Add the above function to your functions.php file and the CSS to style.css. Then call the chart in your template like so: <code>&lt;?php ch_archive_graph(); ?></code></p>
<p>The template tag also includes a few options to make customizing it easier:</p>
<ul>
<li>&#8216;<code>graphYear</code>&#8216;   this is the year of the archive you want to display</li>
<li>&#8216;<code>xIncrement</code>&#8216;   this is the width of the bars in the chart</li>
<li>&#8216;<code>graphHeight</code>&#8216;  this is the height in pixels of the chart</li>
<li>&#8216;<code>limit</code>&#8216;    this is number of posts you want to display</li>
</ul>
<p>Example:<br />
<code>&lt;?php ch_archive_graph('graphYear=2007&#038;xIncrement=40&#038;graphHeight=400&#038;limit=6'); ?></code></p>
<h3>Bonus: For Javascript Charts</h3>
<p>If you need the output for a javascript based chart, you only need to alter things a bit to get a javascript array or months and number of posts, then plug them into whatever charting you want to use.</p>
<pre name="code" class="php">
function ch_count_months_js_output($args = ''){
	global $wpdb, $wp_locale;

	$defaults = array(
		'limit' =&gt; '',
		'before' =&gt; ''
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );


	$where = apply_filters('getarchives_where', &quot;WHERE post_type = 'post' AND post_status = 'publish'&quot;, $r );
	$join = apply_filters('getarchives_join', &quot;&quot;, $r);

	$query = &quot;SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb-&gt;posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit&quot;;
	$key = md5($query);
	$cache = wp_cache_get( 'ch_count_months_js_output' , 'general');

	if ( !isset( $cache[ $key ] ) ) {
		$arcresults = $wpdb-&gt;get_results($query);
		$cache[ $key ] = $arcresults;
		wp_cache_add( 'ch_count_months_js_output', $cache, 'general' );
	} else {
		$arcresults = $cache[ $key ];
	}
	if ( $arcresults ) {
		$arcresults = array_reverse($arcresults);
		$posts = array();
		$months = array();
		foreach ( (array) $arcresults as $arcresult ) {
			$month = sprintf(__('%1$s'), $wp_locale-&gt;get_month($arcresult-&gt;month));
			array_push($months, $month);
			array_push($posts, $arcresult-&gt;posts);
		}
	}	
	print_r($months);
	print_r($posts); 

	echo '&lt;p type=&quot;text/javascript&quot;&gt;'; 
	echo 'var months = [&quot;', join($months,'&quot;,&quot;'), '&quot;];'; 
	echo 'var posts = [', join($posts,','), ']';
	echo '&lt;/p&gt;';
}
</pre>
<blockquote><p>Let me know if you use it or improve it!</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/creating-a-chart-on-your-wordpress-archives-page/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Delay Page Loading with jQuery</title>
		<link>http://curtishenson.com/quick-tip-delay-page-loading-with-jquery/</link>
		<comments>http://curtishenson.com/quick-tip-delay-page-loading-with-jquery/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 01:15:07 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=521</guid>
		<description><![CDATA[On a site I recently worked on I wanted to have an animation before the next page loaded. What I wanted to happen was: user clicks a link, animation plays out, page is loaded normally. It is a nice little effect, but this is probably a trick you want to use sparingly...please...use it sparingly.]]></description>
			<content:encoded><![CDATA[<p>On a site I recently worked on I wanted to have an animation before the next page loaded. What I wanted to happen was: user clicks a link, animation plays out, page is loaded normally. It is a nice little effect, but this is probably a trick you want to use sparingly&#8230;please&#8230;use it sparingly.</p>
<p>This uses the <a href="http://www.evanbot.com/article/jquery-delay-plugin/4">delay</a>, and <a href="http://gsgd.co.uk/sandbox/jquery/easing/">easing</a> plugins for jquery. The below example includes the animation just as an example.</p>
<pre name="code" class="js">
$('#link').click(function(){
        // Get the url of the link
		var toLoad = $(this).attr('href');

			// Do some stuff
			$(this).animate({
				marginRight: '50px',
				marginLeft: '-175px'
			}, 300, 'easeOutSine').animate({
				marginRight: '-38px',
				marginLeft: '-120px'
			}, 500, 'easeOutBounce');
			// Stop doing stuff

        // Wait 700ms before loading the url
		$(this).delay(700, function(){
			window.location = toLoad;
		});

        // Don't let the link do its natural thing
		return false;
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/quick-tip-delay-page-loading-with-jquery/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Dynamic Multi-level Page Menus in WordPress</title>
		<link>http://curtishenson.com/dynamic-multi-level-page-menus-in-wordpress/</link>
		<comments>http://curtishenson.com/dynamic-multi-level-page-menus-in-wordpress/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 00:15:08 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[word]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=497</guid>
		<description><![CDATA[Something I often see while trolling boards (<em>and engaging in flame wars</em>) is the question: "<strong>How do I display a menu with a parent level and child level, but only if the current page actually has child pages?</strong>".]]></description>
			<content:encoded><![CDATA[<p>Something I often see while trolling boards (<em>and engaging in flame wars</em>) is the question: &#8220;<strong>How do I display a menu with a parent level and child level, but only if the current page actually has child pages?</strong>&#8221; or something similar, but better phrased.  The gist is, all the basic WordPress template functions don&#8217;t really do this, at least not very well.  You can use a few functions to get something close, but it often is a compromise with the end result not quite what the designer had envisioned. I say no more!</p>
<h3>What it actually does</h3>
<p>The purpose of this article is to give you a function you can pop into a theme just like a regular template tag (<code>wp_list_pages</code>) but with some changed functionality.  What you&#8217;ll get is a top level menu, nothing fancy, basic use of wp_list_pages really, but this top level is always there.  You also get child menus, as many as you need. The child menus only display if the page actually has children, and it only displays one level of children instead of all of them.</p>
<h3>The beginning of a beast</h3>
<p>I&#8217;m not gonna lie, this is gonna get thick and fast, in fact the code barely makes sense to me and I wrote it. Here&#8217;s the short: we display a top level menu(<em>easy</em>), we check if a page is a child(<em>easy</em>), we check if the page has children itself(<em>weird hack</em>), we count the page&#8217;s parents and display the menu accordingly(<em>huh?</em>).</p>
<h4>The top level</h4>
<p>We&#8217;ll start with the top level menu, this is just a call to the wp_list_pages function, nothing fancy here. Output is generated with an unordered list with a few class names for styling.</p>
<pre class="php" name="code">
//Multi-level pages menu
function wptt_multilevel_menu() {
	global $post;
	// Top level menu is always displayed
	$top_level = wp_list_pages('title_li=&amp;depth=1&amp;sort_column=menu_order&amp;echo=0');

	// Put it all together
	$menu = '&lt;ul class=&quot;menu top_level&quot;&gt;';
	$menu .= $top_level;
	$menu .= '&lt;/ul&gt;';

	print $menu;
}
</pre>
<h4>Displaying the children</h4>
<p>The meat of this example is this next part, displaying the children is in thought a very simple process, in practice it takes a bit of pounding a square peg into a round hole.  We are still using the wp_list_pages function, and most of this code has one purpose, <strong>to determine the right depth to pass to wp_list_pages</strong>.</p>
<p>Initially we&#8217;ll check if a page has any parent pages using <code>$post->ancestors</code> and count the ancestors. I count the ancestors to determine the depth used later. Then check if a page has any more children.  We&#8217;ll then separate those pages with children and those without.</p>
<pre class="php" name="code">
&lt;?php
// Check if a page has any parent pages
	if ($post-&gt;ancestors) {

		// How many ancestors does this page have? Then subtract by 1 to adjust for top level
		$n = count($post-&gt;ancestors);
		$n = $n - 1;

		// Get the page's children, if it has any
		$pages = get_pages();
		$page_children = get_page_children($post-&gt;ID, $pages);

		// Checks if a page has children
		if (!empty($page_children)) {
			$children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;. $post-&gt;ancestors[$n] .&quot;&amp;echo=0&amp;sort_column=menu_order&amp;depth=&quot; . ($n + 2));
		} else { // If the page doesn't have children
			$children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;. $post-&gt;ancestors[$n] .&quot;&amp;echo=0&amp;sort_column=menu_order&amp;depth=&quot; . ($n + 1));
		}

	} else {
		$children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;. $post-&gt;ID .&quot;&amp;echo=0&amp;sort_column=menu_order&amp;depth=1&quot;);
	}
?&gt;
</pre>
<p>All of the counting done above(<em>$n, depth, ancestors, blah blah</em>) is all done in order to display only the first child level. This way you are not showing all the children of the top level page.</p>
<h3>The whole function</h3>
<p>In the final function I&#8217;ve added some output for the children and combined everything above.</p>
<blockquote><p>Updated 4/20/09 &#8211; the function has changed slightly since the explanation above.</p></blockquote>
<pre class="php" name="code">
//Multi-level pages menu
function wptt_multilevel_menu() {
	global $post;
	// Top level menu is always displayed
	$top_level = wp_list_pages('title_li=&amp;depth=1&amp;sort_column=menu_order&amp;echo=0');

	// Get post ancestors 
	$post_ancestors = get_post_ancestors($post);

	// Check if a page has any parent pages
	if ($post_ancestors) {

		//get the top page id
		$top_page = $post_ancestors ? end($post_ancestors) : $post-&gt;ID;

		// How many ancestors does this page have? Counts the array adds one.
		$n = count($post_ancestors) + 1;

		// Get the pages children, if it has any
		$pages = get_pages();
		$page_children = get_page_children($post-&gt;ID, $pages);

		// Checks if a page has children
		if (!empty($page_children)) {
			$children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;. $top_page .&quot;&amp;echo=0&amp;sort_column=menu_order&amp;depth=&quot; . $n);
		} else { // If the page doesn't have children
			$children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;. $top_page .&quot;&amp;echo=0&amp;sort_column=menu_order&amp;depth=&quot; . ($n - 1));
		}

	} else {
		$children = wp_list_pages(&quot;title_li=&amp;child_of=&quot;. $post-&gt;ID .&quot;&amp;echo=0&amp;sort_column=menu_order&amp;depth=1&quot;);
	}

	// Put it all together
	$menu = '&lt;ul class=&quot;menu top_level&quot;&gt;';
	$menu .= $top_level;
	$menu .= '&lt;/ul&gt;';
	// Only show child navigation if there are children
	if ( $children ) {
		$menu .= '&lt;ul class=&quot;menu subpages&quot;&gt;';
		$menu .= $children;
		$menu .= '&lt;/ul&gt;';
	}
	print $menu;
}
</pre>
<h3>The future and spaceships</h3>
<p>That is one way to do multiple level menus in wordpress, right now this function is only using pages, but I will be expanding it to use categories as well.  There are actually quite a few ways I want to expand this in order to make it truly useful.  This function is part of the larger <a href="http://curtishenson.com/wordpress-theme-tools-project-announcement/">WordPress Theme Tools project</a> that I&#8217;m starting. If you have any suggestions for this, find a bug, or know a better way, let me know!</p>
<p><strong>Note</strong>: I&#8217;ve updated the code on 4/20/09 but the function still works the same. As it is right now <strong>the sub pages are displayed in the default nested way</strong> that WordPress naturally does it.  <em>The benefit of the function is that it only shows one level under the parent page instead of hard coding the depth or showing all the children.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/dynamic-multi-level-page-menus-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
		<item>
		<title>WordPress Navigation Helper Function, Comments and Posts</title>
		<link>http://curtishenson.com/wordpress-navigation-helper-function-comments-and-posts/</link>
		<comments>http://curtishenson.com/wordpress-navigation-helper-function-comments-and-posts/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 23:26:25 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=466</guid>
		<description><![CDATA[A quick tip on only displaying navigation blocks when there is actually navigation to be displayed. Oh and a full navigation helper function you can drop into your themes to keep things nice and clean.]]></description>
			<content:encoded><![CDATA[<p>This post started as a quick little tip on how to hide navigation blocks when there weren&#8217;t any pages to actually link to. That was a good post, it was intelligent, well thought out, and helpful. But like all things intelligent, well thought out, and helpful, it was quickly scrapped. </p>
<p>While coding the new theme for curtishenson.com I had a problem, <strong>pagination blocks would show even when there were no pages to link to</strong>(not <em>technically</em> wordpress&#8217; fault), turns out it is a pretty easy fix. For post pagination blocks wrap the navigation in this:</p>
<pre name="code" class="php">
&lt;?php global $wp_query;
	$total_pages = $wp_query-&gt;max_num_pages;
		if ( $total_pages &gt; 1 ) {
			//Your navigation goes here
		}
?&gt;
</pre>
<p>This grabs the total amount pages, checks if it is greater than one, then shows the navigation if there is more than one page. For comment pagination in WordPress 2.7+ do it like this:</p>
<pre name="code" class="php">
$total_pages = get_comment_pages_count();
	if ( $total_pages &gt; 1 ) {
		//Your navigation goes here
	}
?&gt;
</pre>
<p>The subtle difference is the use of the <strong>get_comment_pages_count</strong> function. Otherwise you&#8217;re just checking to see if there is more than one page.</p>
<h3>A Helper Function</h3>
<p>The first time I saw a helper it was in a ruby on rails program. Seemed like a good idea, don&#8217;t know why I hadn&#8217;t used this most basic implementation of DRY (<em>Don&#8217;t Repeat Yourself</em>) theory in WordPress themes. So while I was copy and pasting this code I decided it would be <strong>much easier to lump it into one function</strong>. The benefits: lighter template files, change the function once and the whole site changes. </p>
<p>This HTML bits will probably need to be changed to your liking, but this little diddy should help anyone with their themes. Just copy and paste the function in your <strong>functions.php</strong> file, then call it in your theme in place of the navigation like so: <code>&lt;?php ch_navigation_helper(); ?></code></p>
<p>I have some ideas to extend this into a truly helpful &#8230;helper. I&#8217;ll be including it in my new <a href="http://curtishenson.com/wordpress-theme-tools-project-announcement/">WP Theme Tools Project</a> for sure. If you extend it let me know!</p>
<blockquote><p>Note: This function only works with WordPress 2.7.1</p></blockquote>
<pre name="code" class="php">
&lt;?php
// Navigation Helper Function 
//http://curtishenson.com/wordpress-navigation-helper-function-comments-and-posts  
function ch_navigation_helper(){
	global $wp_query;
	// For templates like index, search, archive, etc.
	if ( !is_singular() ) {
		$total_pages = $wp_query-&gt;max_num_pages;
			if ( $total_pages &gt; 1 ) { 
			$s = '';
			$s .= '&lt;div class=&quot;navigation clearfix&quot;&gt;';
			$s .= '&lt;span class=&quot;alignleft&quot;&gt;' . get_next_posts_link('Previous Entries') . '&lt;/span&gt;';
			$s .= '&lt;span class=&quot;alignright&quot;&gt;' . get_previous_posts_link('Newer Entries') . '&lt;/span&gt;';
			$s .= '&lt;/div&gt;';
			echo $s;
		}
	}

	// For paginated comments in WP 2.7+
	if ( is_singular() &amp;&amp; get_option('page_comments') ) {
		$total_pages = get_comment_pages_count();
		if ( $total_pages &gt; 1 ) { 
			$s = '';
			$s .= '&lt;div class=&quot;navigation clearfix&quot;&gt;';
			$s .= '&lt;div class=&quot;alignleft&quot;&gt;';
			$s .= get_previous_comments_link('Older Comments');
			$s .= '&lt;/div&gt;';
			$s .= '&lt;div class=&quot;alignright&quot;&gt;';
			$s .= get_next_comments_link('Newer Comments');
			$s .= '&lt;/div&gt;&lt;/div&gt;';
			echo $s;
		} 
	}
}

?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/wordpress-navigation-helper-function-comments-and-posts/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WordPress Theme Tools Project Announcement</title>
		<link>http://curtishenson.com/wordpress-theme-tools-project-announcement/</link>
		<comments>http://curtishenson.com/wordpress-theme-tools-project-announcement/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 20:44:02 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=457</guid>
		<description><![CDATA[A new project for WordPress theme developers which will make creating advanced themes easier and quicker. The project will be a library of code that can be dropped into a theme and give the developer quick access to things like theme options, custom widgets, and tailor made functions.]]></description>
			<content:encoded><![CDATA[<p>An &#8220;<em>announcement</em>&#8221; of a project, sounds exciting doesn&#8217;t it? Well if you develop WordPress themes you should be excited, or at least somewhat amused.  I&#8217;m planning on developing a set of what I call &#8220;tools&#8221; for you WordPress themers out there. It is still in it&#8217;s planning stage at the moment but I&#8217;m going to list what it is going to have so far because <strong>I want your input</strong> on what you want, and how you think it should work.</p>
<h3>The Basic Idea</h3>
<p>When I develop themes I spend a lot of time doing the same things, or copy and pasting code from my other themes and tweaking. Things like <strong>theme options, basic functions, filters, widgets</strong>.  I also have had some trouble keeping things like widgets up to date(thank God WordPress is so forgiving).</p>
<p>I want to build a library that can be dropped into any theme, and be <strong>easily customized</strong> to suit the needs of that theme. This is the basic idea behind the tools project.</p>
<h3>Theme Options</h3>
<p>I think theme options are an integral part of modern WordPress themes.  Themes are more complex than ever and I can&#8217;t imagine developing a theme without options.  Theme options can be a pain, but they don&#8217;t have to be. The tools project&#8217;s first feature (<em>and already almost done</em>) is a library which makes creating theme options as easy as creating a few arrays.  Drop in the files, customize a file and you are good to go. No more searching through long files of code.</p>
<h3>Basic Functions and Filters</h3>
<p>Custom functions can greatly help a theme designer, whether it is doing complex things or just helping clean up the source code.  I have a few functions and filters planned already, but this <strong>could definitely use some input</strong> as I&#8217;m sure other people could add to this part.</p>
<h3>Widgets</h3>
<p>Custom widgets are nice&#8230;especially when they work right. Custom widgets are also a huge selling point (or give away point??) for themes.  And custom widgets are also usually a huge pain in my ass.  It is a lot of code, and a lot of my code is now outdated due to WordPress 2.7.  I&#8217;m not sure how easily customizable the widgets will be though, any ideas on how that could work are welcome.</p>
<h3>Widget Areas</h3>
<p>So far this is just a bunch of arrays premade for the theme.  Not sure if there is anything else that can make this basic feature better.</p>
<h3>Your Input</h3>
<p>That is what I currently have in mind for the project, however I&#8217;d like to extend that further.  l&#8217;ll need the input of people who build themes. <strong>What do you want? How do you think it should work? Any ideas for more features?</strong> </p>
<p>I&#8217;m going to upload this on github once I have a good, functioning base so people will be able to branch it and commit changes and updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/wordpress-theme-tools-project-announcement/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Separating and Hiding Trackbacks with Jquery in WordPress 2.7</title>
		<link>http://curtishenson.com/separating-and-hiding-trackbacks-with-jquery-in-wordpress-27/</link>
		<comments>http://curtishenson.com/separating-and-hiding-trackbacks-with-jquery-in-wordpress-27/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 16:00:33 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=432</guid>
		<description><![CDATA[If you're designing and coding themes for WordPress, please, I beg you, for love of all that is digitized and Tron like, separate your trackbacks and pingbacks from your comment threads. This tutorial goes over separating comments and pings and adding a little jQuery spice.]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re designing and coding themes for WordPress, please, I beg you, for love of all that is digitized and Tron like, separate your trackbacks and pingbacks from your comment threads. There is nothing more frustrating than having to navigate through a horde of unholy spam links to see the next comment in a thread. I also personally believe(ie I have no proof whatsoever) that a comment threat mucked with trackbacks correlates directly with less commenting. But trackbacks aren&#8217;t all bad, some people (not me) use them to find out more about the blog post, theme, story, whatever&#8230;so I wouldn&#8217;t just toss them aside like fruit cake.</p>
<p>If you look at most new well thought out themes, trackbacks are separated into another tab, or somehow minimized/hidden from the user that doesn&#8217;t want them. WordPress 2.7 changed the commenting code quite a bit, and now separating everything is even easier. Add a little jQuery magic and you can hide and show those trackbacks on demand. Enough with this banter, lets rock out with our text-editor out.</p>
<h3>First a little catchup</h3>
<p>So things are a wee bit different in the ol&#8217; comment file in WordPress 2.7. I highly suggest taking a peek at Otto&#8217;s <a href="http://ottodestruct.com/blog/2008/09/29/wordpress-27-comments-enhancements/">WordPress 2.7 Comments Enhancements</a> if you haven&#8217;t already. He outlines how the new comment loop works, and all the spiffy javascript for threaded comments.</p>
<p>Once you got a grasp on the comment changes in 2.7, checkout Matt&#8217;s article on <a href="http://sivel.net/2008/10/wp-27-comment-separation/">separating pings from comments</a>. I&#8217;m not going to go into too much detail so if you find yourself not understanding a part of the code, try checking out those articles.</p>
<h3>Separation makes the heart grow fonder of pings</h3>
<p>I think that is the saying. Lets start with the comment loop, first the whole thing, </p>
<pre name="code" class="php">
if ( have_comments() ) : ?&gt;
	&lt;h3 class=&quot;comment_title&quot;&gt;&lt;?php comments_number('No Comments', 'One Comment', '% Comments' );?&gt;&lt;/h3&gt;
		&lt;ol class=&quot;commentlist&quot; id=&quot;singlecomments&quot;&gt;
			&lt;?php wp_list_comments(array('avatar_size'=&gt;48, 'reply_text'=&gt;'Reply', 'type'=&gt;'comment')); ?&gt;
		&lt;/ol&gt;

	&lt;h3 class=&quot;trackback_title&quot;&gt;Trackbacks / Pingbacks&lt;/h3&gt;
	&lt;a href=&quot;#pings&quot; class=&quot;show_trackbacks&quot;&gt;show trackbacks&lt;/a&gt;
		&lt;ol id=&quot;pings&quot; class=&quot;trackback&quot;&gt;
			&lt;?php wp_list_comments('type=pings'); ?&gt;
		&lt;/ol&gt;

	&lt;div class=&quot;comments-navigation&quot;&gt;
		&lt;div class=&quot;alignleft&quot;&gt;&lt;?php previous_comments_link() ?&gt;&lt;/div&gt;
		&lt;div class=&quot;alignright&quot;&gt;&lt;?php next_comments_link() ?&gt;&lt;/div&gt;
	&lt;/div&gt;
 &lt;?php else : // this is displayed if there are no comments so far ?&gt;

	&lt;?php if ('open' == $post-&gt;comment_status) :
		// If comments are open, but there are no comments.
	else : 
		// comments are closed 
	endif;
endif;
</pre>
<p>There is the comment loop with the trackbacks already separated. The only trick to the separation is setting the &#8216;<strong>type</strong>&#8216; option for the <code>wp_list_comments</code> function. Set the &#8216;type&#8217; to &#8216;comment&#8217;, for comments, and pings for &#8230;well pings(trackbacks). Simple enough right?  Let&#8217;s take a closer look at the HTML.</p>
<pre name="code" class="html">
&lt;h3 class=&quot;comment_title&quot;&gt;&lt;?php comments_number('No Comments', 'One Comment', '% Comments' );?&gt;&lt;/h3&gt;
		&lt;ol class=&quot;commentlist&quot; id=&quot;singlecomments&quot;&gt;
			&lt;?php wp_list_comments(array('avatar_size'=&gt;48, 'reply_text'=&gt;'Reply', 'type'=&gt;'comment')); ?&gt;
		&lt;/ol&gt;

	&lt;h3 class=&quot;trackback_title&quot;&gt;Trackbacks / Pingbacks&lt;/h3&gt;
	&lt;a href=&quot;#pings&quot; class=&quot;show_trackbacks&quot;&gt;show trackbacks&lt;/a&gt;
		&lt;ol id=&quot;pings&quot; class=&quot;trackback&quot;&gt;
			&lt;?php wp_list_comments('type=pings'); ?&gt;
		&lt;/ol&gt;
</pre>
<p>This is really the meat of the code, you can see the two blocks of code, one for comments and one for pings. The only real differences are setting the &#8216;type&#8217; for wp_list_comments and changing the id and class names for styling. There is also one addition for the pings, a link to show them(it has a class of &#8216;show_trackbacks&#8217;). You can either put this link in the actual code, or inject it using javascript.</p>
<h3>The jQuery</h3>
<p>There&#8217;s a few ways to do this but I&#8217;m going to go with a simple slide up and slide down. First we&#8217;ll hide the trackbacks by calling <code>slideUp()</code> then add a function to detect the click on our show_trackbacks link which will call <code>slideDown()</code>.</p>
<pre name="code" class="js">
$('ol.trackback').slideUp();
$('.show_trackbacks').click(function(){
	$('ol.trackback').slideDown();
});
</pre>
<p>That&#8217;s it?? Yeah, pretty simple actually, so I&#8217;ll leave you with something else useful. A full comment file ready for wordpress 2.7.</p>
<h3>The whole thing</h3>
<pre name="code" class="php">
&lt;?php // Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) &amp;&amp; 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
	die ('Please do not load this page directly. Thanks!');
if ( post_password_required() ) { ?&gt;
	&lt;p class=&quot;nocomments&quot;&gt;This post is password protected. Enter the password to view comments.&lt;/p&gt;
&lt;?php
	return;
}

// add a microid to all the comments
function comment_add_microid($classes) {
	$c_email=get_comment_author_email();
	$c_url=get_comment_author_url();
	if (!empty($c_email) &amp;&amp; !empty($c_url)) {
		$microid = 'microid-mailto+http:sha1:' . sha1(sha1('mailto:'.$c_email).sha1($c_url));
		$classes[] = $microid;
	}
	return $classes;	
}
add_filter('comment_class','comment_add_microid');

//Change date format
function change_comment_date($datestring, $dateformat) {
global $comment;
return mysql2date('F j y', $comment-&gt;comment_date);
}
add_filter('get_comment_date','change_comment_date',10,2);

// show the comments
if ( have_comments() ) : ?&gt;
	&lt;h3 class=&quot;comment_title&quot;&gt;&lt;?php comments_number('No Comments', 'One Comment', '% Comments' );?&gt;&lt;/h3&gt;
		&lt;ol class=&quot;commentlist&quot; id=&quot;singlecomments&quot;&gt;
			&lt;?php wp_list_comments(array('avatar_size'=&gt;48, 'reply_text'=&gt;'Reply', 'type'=&gt;'comment')); ?&gt;
		&lt;/ol&gt;

	&lt;h3 class=&quot;trackback_title&quot;&gt;Trackbacks / Pingbacks&lt;/h3&gt;
	&lt;a href=&quot;#pings&quot; class=&quot;show_trackbacks&quot;&gt;show trackbacks&lt;/a&gt;
		&lt;ol id=&quot;pings&quot; class=&quot;trackback&quot;&gt;
			&lt;?php wp_list_comments('type=pings'); ?&gt;
		&lt;/ol&gt;

	&lt;div class=&quot;comments-navigation&quot;&gt;
		&lt;div class=&quot;alignleft&quot;&gt;&lt;?php previous_comments_link() ?&gt;&lt;/div&gt;
		&lt;div class=&quot;alignright&quot;&gt;&lt;?php next_comments_link() ?&gt;&lt;/div&gt;
	&lt;/div&gt;
 &lt;?php else : // this is displayed if there are no comments so far ?&gt;

	&lt;?php if ('open' == $post-&gt;comment_status) :
		// If comments are open, but there are no comments.
	else : 
		// comments are closed 
	endif;
endif; 

if ('open' == $post-&gt; comment_status) : 

// show the form
?&gt;
&lt;div id=&quot;respond&quot;&gt;&lt;h3&gt;&lt;?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?&gt;&lt;/h3&gt;

&lt;div id=&quot;cancel-comment-reply&quot;&gt;
	&lt;small&gt;&lt;?php cancel_comment_reply_link(); ?&gt;&lt;/small&gt;
&lt;/div&gt;

&lt;?php if ( get_option('comment_registration') &amp;&amp; !$user_ID ) : ?&gt;

&lt;p&gt;You must be &lt;a href=&quot;&lt;?php echo get_option('siteurl'); ?&gt;/wp-login.php?redirect_to=&lt;?php echo urlencode(get_permalink()); ?&gt;&quot;&gt;logged in&lt;/a&gt; to post a comment.&lt;/p&gt;

&lt;?php else : ?&gt;

&lt;form action=&quot;&lt;?php echo get_option('siteurl'); ?&gt;/wp-comments-post.php&quot; method=&quot;post&quot; id=&quot;commentform&quot; class=&quot;span-17&quot;&gt;

	&lt;div&gt;
	&lt;?php comment_id_fields(); ?&gt;
	&lt;input type=&quot;hidden&quot; name=&quot;redirect_to&quot; value=&quot;&lt;?php echo htmlspecialchars($_SERVER[&quot;REQUEST_URI&quot;]); ?&gt;&quot; /&gt;&lt;/div&gt;

	&lt;p&gt;&lt;small&gt;&lt;strong&gt;XHTML:&lt;/strong&gt; You can use these tags: &lt;?php echo allowed_tags(); ?&gt;&lt;/small&gt;&lt;/p&gt;

	&lt;p&gt;&lt;textarea name=&quot;comment&quot; id=&quot;comment&quot; cols=&quot;10&quot; rows=&quot;10&quot; tabindex=&quot;4&quot;&gt;&lt;/textarea&gt;&lt;/p&gt;

	&lt;?php if (get_option(&quot;comment_moderation&quot;) == &quot;1&quot;) { ?&gt;
	 &lt;p&gt;&lt;small&gt;&lt;strong&gt;Please note:&lt;/strong&gt; Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.&lt;/small&gt;&lt;/p&gt;
	&lt;?php } ?&gt;


&lt;?php if ( $user_ID ) : ?&gt;

&lt;p class=&quot;loggedin&quot;&gt;Logged in as &lt;a href=&quot;&lt;?php echo get_option('siteurl'); ?&gt;/wp-admin/profile.php&quot;&gt;&lt;?php echo $user_identity; ?&gt;&lt;/a&gt;.
&lt;a href=&quot;&lt;?php echo wp_logout_url(get_permalink()); ?&gt;&quot; title=&quot;Log out of this account&quot;&gt;Logout &amp;raquo;&lt;/a&gt;&lt;/p&gt;

&lt;?php else : ?&gt;

&lt;p&gt;&lt;label for=&quot;author&quot;&gt;&lt;small&gt;Name &lt;?php if ($req) echo &quot;(required)&quot;; ?&gt;&lt;/small&gt;&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;author&quot; id=&quot;author&quot; value=&quot;&lt;?php echo $comment_author; ?&gt;&quot; size=&quot;22&quot; tabindex=&quot;1&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;label for=&quot;email&quot;&gt;&lt;small&gt;Email &lt;?php if ($req) echo &quot;(required)&quot;; ?&gt;&lt;/small&gt;&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; value=&quot;&lt;?php echo $comment_author_email; ?&gt;&quot; size=&quot;22&quot; tabindex=&quot;2&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;label for=&quot;url&quot;&gt;&lt;small&gt;Website&lt;/small&gt;&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;url&quot; id=&quot;url&quot; value=&quot;&lt;?php echo $comment_author_url; ?&gt;&quot; size=&quot;22&quot; tabindex=&quot;3&quot; /&gt;&lt;/p&gt;

&lt;?php endif; ?&gt;

&lt;p&gt;&lt;input name=&quot;submit&quot; type=&quot;submit&quot; id=&quot;submit&quot; tabindex=&quot;5&quot; value=&quot;Submit Comment&quot; /&gt;&lt;/p&gt;
&lt;?php do_action('comment_form', $post-&gt;ID); ?&gt;
&lt;/div&gt;

&lt;/form&gt;

&lt;?php 
endif;

endif;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/separating-and-hiding-trackbacks-with-jquery-in-wordpress-27/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>WordPress Posts Navigation Quick Tip</title>
		<link>http://curtishenson.com/wordpress-posts-navigation-quick-tip/</link>
		<comments>http://curtishenson.com/wordpress-posts-navigation-quick-tip/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 02:39:45 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=381</guid>
		<description><![CDATA[ Say you want to use the next_posts_link() and previous_posts_link() functions to display your post navigation. But you want to use some clever looking arrow images(<em>or just plain boring text</em>). You also want the images(<em>or that plain boring text</em>) grayed out when there are no more pages to link to. ]]></description>
			<content:encoded><![CDATA[<p>Say you want to use the <code>next_posts_link()</code> and <code>previous_posts_link()</code> functions to display your post navigation. But you want to use some clever lookin&#8217; arrow images(<em>or just plain boring text</em>). You also want the images(<em>or that plain boring text</em>) grayed out when there are no more pages to link to. </p>
<p>Whoa there&#8217;s the problem, the <code>next_posts_link()</code> and <code>previous_posts_link()</code> functions don&#8217;t output anything when there are no more pages to link to. A little PHP to the rescue.</p>
<h3>The Code</h3>
<p>The code is pretty easy, just an <strong>if else</strong> statement. We are going to use the <code>get_next_posts_link()</code> and <code>get_previous_posts_link()</code> to test if there is a link or not.</p>
<pre class="php" name="code">
&lt;?php
// Check for a link to older posts
		if ( get_next_posts_link() ) {
// If there is a link to older pages output this code
			echo '<span class="old_posts">';
				next_posts_link('Previous', '0');
			echo '</span>';
		} else {
 // If there isn't a link output our own code
			echo '<span class="no_old_posts">no older posts</span>';
		};

// Check for a link to newer posts
		if ( get_previous_posts_link() ) {
 // If there is a link to older pages output this code
			echo '<span class="new_posts">';
				previous_posts_link('Newer', '0');
			echo '</span>';
		} else {
 // If there isn't a link output our own code
			echo '<span class="no_new_posts">no newer posts</span>';
	};
?>
</pre>
<p>To break it down a bit, there is an <strong>if else</strong> block for each link. The <strong>if</strong> statement checks <code>get_next_posts_link()</code> or <code>get_previous_posts_link()</code>, if it returns a link we call <code>next_posts_link()</code> or <code>previous_posts_link()</code> if it doesn&#8217;t we echo our own code.</p>
<p>Something to keep in mind is that normally &#8220;<em>next</em>&#8221; refers to older posts and &#8220;<em>previous</em>&#8221; refers to newer posts, which can be confusing while looking at the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/wordpress-posts-navigation-quick-tip/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>New WordPress 2.7 Functions</title>
		<link>http://curtishenson.com/new-wordpress-27-functions/</link>
		<comments>http://curtishenson.com/new-wordpress-27-functions/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 01:33:23 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[themes]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=369</guid>
		<description><![CDATA[WordPress 2.7 includes a few new exciting features and functions for theme developers. I go over how to use these functions and give a few links on learning more about WordPress 2.7.]]></description>
			<content:encoded><![CDATA[<p>WordPress 2.7 is approaching us and there are some new functions for theme developers. I&#8217;m so excited, are you excited? I just can&#8217;t hide it.</p>
<h3>Easy Post Classes</h3>
<p>Something I really didn&#8217;t expect was the post_class() function. This makes the almost obligatory class=&#8221;post&#8221; a thing of the past, and replaces it with something infinitely more useful. Straight from the codex:</p>
<blockquote><p>This includes several different classes of value: post, hentry (for hAtom microformat pages), category-X (where X is the slug of every category the post is in), and tag-X (similar, but with tags). It also adds &#8220;sticky&#8221; for posts marked as sticky posts.</p></blockquote>
<p>This is great for keyword stuff&#8230;err&#8230;I mean SEO. Also it will make styling posts simple and straightforward. This is some functionality that isn&#8217;t new to some themes, but now that its part of the core, it is oh so much easier and cleaner.</p>
<h4>How to use it</h4>
<p>This one is simple enough, stick it inside the loop where you would normally have a class=&#8221;post&#8221; like so:</p>
<pre class="php" name="code">&lt;div &lt;?php post_class(); ?>></pre>
<p>Say you want to add a special class, so your posts with a certain custom field are displayed differently than a post without the custom field. Easy enough, you can pass along a single class name, space separated list, or an array of classes:</p>
<pre class="php" name="code">&lt;div &lt;?php post_class('special_class'); ?>>
&lt;div &lt;?php post_class('special_class class2 class3 class4'); ?>>
&lt;div &lt;?php post_class($my_array); ?>></pre>
<p>Great! But I want to use it outside of the loop, to display something in my sidebar on single post pages cause I&#8217;m cool like that. WordPress has got you covered there too, you can pass a post ID as a second parameter:</p>
<pre class="php" name="code">&lt;div &lt;?php post_class('', $post_id); ?>></pre>
<p>I got a feeling this is going to open up some very cool things when people start to play with it.</p>
<h3>A Logout Link</h3>
<p>OK so I think this one is relatively boring compared to the rest, but I know this will actually be useful in certain applications. It is the almighty wp_logout_url() function. It does just what you think it does, provides a <em>protected</em> log out link for your users. Use is simple just put <code>&lt;?php wp_logout_url(); ?></code> where you want it.</p>
<h3>Page Menus</h3>
<p>Another new function is actually a wrapper for wp_list_pages(). The wp_page_menu() can be used pretty much the same as wp_list_pages(), but one useful little add is the ability to a link to the homepage:</p>
<pre class="php" name="code">&lt;?php wp_page_menu('show_home=1'); ?></pre>
<h3>HTTP API</h3>
<p>There&#8217;s also a new http api for plugins that looks like it could be useful. From the codex:</p>
<blockquote><p>The HTTP API is an attempt to standardize the HTTP requests and responses for WordPress. It will eventually obsolete Snoopy and deprecate the other functions in WordPress. That is, once the HTTP API is completely stable. </p></blockquote>
<p>I haven&#8217;t got a chance to really look into any of these, but you should be aware of them as they could be a huge part of whatever plug-in you are writing.</p>
<h3>Comment Enhancements</h3>
<p>I&#8217;ve saved the best for last. WordPress 2.7 has brought some much wanted comment love, threaded, paged, etc. Themes do have support all this although, which will make some of very busy. Instead of repeating all the info about the comment updates, just head over to the <a href="http://ottodestruct.com/blog/2008/09/29/wordpress-27-comments-enhancements/">WordPress 2.7 Comments Enhancements</a> post from Otto.</p>
<h3>More&#8230;</h3>
<p>That is all I got right now, but there are more new features you may be of interest to you in WordPress 2.7. For a complete look at the features list check out the <a href="http://codex.wordpress.org/Version_2.7">codex page on WordPress 2.7</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/new-wordpress-27-functions/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Complex WordPress Conditional Tags</title>
		<link>http://curtishenson.com/complex-wordpress-conditional-tags/</link>
		<comments>http://curtishenson.com/complex-wordpress-conditional-tags/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 21:54:31 +0000</pubDate>
		<dc:creator>Curtis Henson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[conditionals]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://curtishenson.com/?p=281</guid>
		<description><![CDATA[The WordPress conditional tags are some of the most powerful tools a theme designer can master. As WordPress themes get more complicated and more CMS like, everyone will eventually run into the need for conditionals.]]></description>
			<content:encoded><![CDATA[<p>The WordPress conditional tags are some of the most powerful tools a theme designer can master. As WordPress themes get more complicated and more CMS like, everyone will eventually run into the need for conditionals. In my previous post I showed you <a href="http://curtishenson.com/wordpress-conditional-tags-write-less-code/">how to write less code</a> using conditional tags and the WordPress hierarchy. Quite a few things have changed since that post, and this time I&#8217;m going to show you some more advanced ways to use conditional tags.</p>
<h3>What&#8217;s New?</h3>
<p>The WordPress dev team heard the cries of the masses and has added new conditional tags to the core.  A few include:</p>
<pre class="php" name="code">&lt;?
is_front_page()
is_single(array(17,'beef-stew','Irish Stew'))
is_page(array(42,'about-me','About Me And Joe'))
is_page_template() ?></pre>
<p>Head on over to the <a href="http://codex.wordpress.org/Conditional_Tags">codex conditionals page</a> for a full list. The most important new tags are the ones which allow you to use arrays. In the past you may have had to use <a href="http://curtishenson.com/how-i-did-multiple-feature-categories-in-checkmate/">complex code</a> to achieve the same result. The ability to filter content by several pages/categories/tags is incredibly useful especially in building large websites. The Codex does a good job at explaining the new tags so I won&#8217;t go into that here.</p>
<h3>How&#8217;s Your PHP?</h3>
<p>If you theme WordPress you probably know at least some basic PHP. The most basic and useful PHP you can learn are <a href="http://us3.php.net/language.operators.comparison">comparison operators</a>. The operators will return <strong>true</strong> or <strong>false</strong> and work the same way as the WordPress conditional tags.  </p>
<p>Let&#8217;s say you wanted some text to only show on the home page(<em>ID is 42</em>) and your about page. One way to do this is:</p>
<pre class="php" name="code"><code>&lt;?
if ( is_page( array (42,'About') ) ){
	echo "Hello World";
}</code></pre>
<p>Lets say you <strong>didn&#8217;t know the ID of the page or the name</strong>, maybe it is in a theme and you want the user to set where the text appears. In this example <code>$text_pages</code> is a list set somewhere either by the user or some other function.</p>
<pre class="php" name="code"><code>&lt;?
$text_pages = get_option('pages');

if ( is_page( array($text_pages) ) ){
	echo "Hello World";
}
</code></pre>
<h4>More complex examples</h4>
<p>OK so far pretty basic stuff. Lets see something more complicated. We have text we want to show on a static home page, some posts <strong>in</strong> a certain category, but not in the search pages. Using PHP comparison operators and WordPress conditionals this is easy.</p>
<pre class="php" name="code"><code>&lt;?
if ( (is_front_page() || in_category('3') &#038;&#038; !( is_search() ) ) {
	echo "Hello World";
}
</code></pre>
<p>Reading this in English goes like so: If is a static home page, or(||) in category 3 and(&#038;&#038;) is not(!) a search page. The exclamation mark is a shortcut for does not equal(!=).</p>
<p>As you can see developing complex conditionals can be very powerful, and can also save you from writing a bunch of repeated code. Lets take it even further and use some <strong>variables</strong> now.</p>
<p>Lets say you want the user to choose if there is a feature post displayed. You also want them to be able to set the categories used for a feature post. You also want don&#8217;t want the feature story repeating itself while paging. To accomplish this we&#8217;re going to use a combination of variables, WordPress conditionals, and some if else statements.</p>
<pre class="php" name="code"><code>&lt;?
$feature = get_option('feature');  // Gets the option to display feature post.
	if( ($feature == 'Yes') &#038;&#038; !(is_paged()) ) { //Excludes the feature post when paging through posts
		$feature_cats = get_option('feature_cats'); // Gets list of feature categories
		query_posts(array('category__in' => array($feature_cats)));
		//The loop and post formatting
  	}
</code></pre>
<h3>Making Your Own Conditionals</h3>
<p>If you really want to get dirty, you can form your own conditionals. The Codex hints at this ability with this example:</p>
<pre class="php" name="code"><code>!empty($post->post_excerpt) </code></pre>
<p>Pretty simple right? If the post excerpt is empty this will return <strong>false</strong>. Likewise removing the <strong>!</strong> will then return false for anything that <strong>has an excerpt</strong>. </p>
<p>With a basic understanding of if else statements, and a not so basic understanding of WordPress functions you could create a conditional statement for just about anything granted you had something to compare to get a true or false statement.</p>
<p>Lets come up with another example. Say you want to display a special title whenever a post has approved comments.</p>
<pre class="php" name="code"><code>
&lt;?php $foo = get_approved_comments($post->ID);
			if ( !empty($foo) ) {
				echo "&lt;h1>I Gots Comments!&lt;/h1>";
				} ?>
</code></pre>
<h3>Quick Comparison Operators Overview</h3>
<p>The <a href="http://us3.php.net/language.operators.comparison">php comparison operators</a> article goes into more detail but I&#8217;ll give you quick overview from a WordPress point of view.</p>
<p>When using these operators with WordPress conditional tags and if else statements keep track of your parenthesis! I&#8217;ve strung together quite a long string which ended in an equally long string of parenthesis, which will be a headache to decode later.</p>
<p>There are a few operators that are used more often. These are: equal( <strong>==</strong> ), not equal (<strong> !=</strong> ), or( <strong>||</strong> ), and( <strong>&#038;&#038;</strong> ). Using these four you can construct some heavy conditionals. </p>
<p>Grouping is important! Just like math, you can group operators and conditionals to get different true or false statements. ex. <code>(in_category(42) &#038;&#038; !(is_search()) || is_archive())</code></p>
<p>Use <strong>!()</strong>, <strong>!empty()</strong>, <strong>empty()</strong> to achieve some more complex conditionals and create your own conditional statements.</p>
<h3>The End</h3>
<p>So there are some examples of complex WordPress conditionals, comparison operators, booleans, if elses, and some pie(<em>update: I ate all the pie</em>). This isn&#8217;t a complete list of what is possible, infact I don&#8217;t think it even scratches the surface. Conditionals are great, and are even more powerful than ever. </p>
]]></content:encoded>
			<wfw:commentRss>http://curtishenson.com/complex-wordpress-conditional-tags/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
