<?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>SofaRider &#187; wordpress navigation</title>
	<atom:link href="http://rider.sofarider.com/tag/wordpress-navigation/feed/" rel="self" type="application/rss+xml" />
	<link>http://rider.sofarider.com</link>
	<description>WordPress Themes, Widgets, Development &#124; WEB &#38; Graphic Design</description>
	<lastBuildDate>Wed, 14 Oct 2009 08:40:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to build sequential navigation in WordPress</title>
		<link>http://rider.sofarider.com/blog/wordpress-tips/how-to-build-sequential-navigation-in-wordpress/</link>
		<comments>http://rider.sofarider.com/blog/wordpress-tips/how-to-build-sequential-navigation-in-wordpress/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 07:56:24 +0000</pubDate>
		<dc:creator>Feeleep</dc:creator>
				<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[sequential]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress navigation]]></category>

		<guid isPermaLink="false">http://rider.sofarider.com/?p=226</guid>
		<description><![CDATA[What is exactly &#8217;sequential navigation&#8217;? From the navigation point of view, imagine category which has &#8216;n&#8217; number of sub-categories and each of these sub-categories may have &#8216;n&#8217; number of sub-sub-categories&#8230;etc. From programmer&#8217;s point of view it&#8217;s a nested list whose list item may contain another nested list and so on. Personally, I&#8217;m not a fan [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://rider.sofarider.com/wp-content/uploads/2009/07/naef_animal_puzzle_LRG-200x200.jpg" alt="naef_animal_puzzle_LRG" title="naef_animal_puzzle_LRG" width="200" height="200" class="alignnone size-thumbnail wp-image-228" />What is exactly &#8217;sequential navigation&#8217;? From the navigation point of view, imagine category which has &#8216;n&#8217; number of sub-categories and each of these sub-categories may have &#8216;n&#8217; number of sub-sub-categories&#8230;etc. From programmer&#8217;s point of view it&#8217;s a nested list whose list item may contain another nested list and so on. Personally, I&#8217;m not a fan of nested list, it makes the site ugly. Branched or multi-level drop-down menu is OK, however it keeps child categories/pages always hidden.</p>
<p>
And here it comes sequential navigation as quite handy solution. I like to use it in conjunction with <a href="http://rider.sofarider.com/blog/wordpress-tips/easy-breadcrumbs/">breadcrumbs</a> so there&#8217;s no chance site visitor gets &#8216;lost&#8217;. As you know, in WordPress categories and pages can have &#8216;children&#8217;, up to 999 levels &#8211; as I recall &#8211; please correct me if I am wrong. Of course, you&#8217;ll never need so many navigation levels but I&#8217;m sure 3 are quite often.
</p>
<p>
Before showing the code, I would like to explain the logic behind sequential navigation. Here&#8217;s an illustration &#8211; just to show you what we are up to.<br />
<a href="http://rider.sofarider.com/wp-content/uploads/2009/07/sequential_navig.png" rel="shadowbox[post-226];player=img;"><img src="http://rider.sofarider.com/wp-content/uploads/2009/07/sequential_navig.png" alt="sequential_navig" title="sequential_navig" width="598" height="329" class="alignnone size-full wp-image-227" /></a>
</p>
<blockquote><p>Our goal is to display only the first level children of selected category, no matter how &#8216;deep&#8217; we are.</p></blockquote>
<p>
Parent category (or page) will always be displayed as a title, indicating current menu set. Hopefully it does make sense to you. It doesn&#8217;t? Later you will be able to read how easily is to implement it into your own site&#8230;
</p>
<h2>The code</h2>
<p>Code is well commented so there shouldn&#8217;t be a problem to understand the logic&#8230;</p>
<pre>
<code>
&lt;?php
	// is there a page or category? both may have childeren
	if( is_category() ) {
		// if this category has childeren
		$categ_object = get_category( get_query_var( 'cat' ), false );
		$list_subcats = wp_list_categories( 'title_li=&amp;depth=1&amp;echo=0&amp;child_of=' . (int)$categ_object-&gt;cat_ID );
		// wordpress never returns null or empty string. If children, &lt;a&gt; tag will be found, otherwise string is returned.
		preg_match_all( '|&lt;a.*?href=[\'&quot;](.*?)[\'&quot;].*?&gt;|i', $list_subcats, $m );
		if( !$m[ 1 ] ) {
			// there are no subcategories. Why?
			// this is either the last child or this category really doesn't have subcategories
			// last child must have a parent, right?
				if( (int)$categ_object-&gt;category_parent &gt; 0 ) {
					// we'll need parent category name for the title, extract name via category ID
					$parent_cat_name = $wpdb-&gt;get_var( &quot;SELECT name FROM $wpdb-&gt;terms WHERE term_id=&quot; . (int)$categ_object-&gt;category_parent );
?&gt;
					&lt;div class=&quot;box&quot;&gt;
					&lt;h1&gt;&lt;?php echo $parent_cat_name; ?&gt;&lt;/h1&gt;
					&lt;ul class=&quot;subnavigation&quot;&gt;
					&lt;?php wp_list_categories( 'title_li=&amp;depth=1&amp;child_of=' . (int)$categ_object-&gt;category_parent ); ?&gt;
					&lt;/ul&gt;
					&lt;/div&gt;
&lt;?php
				} // else...no else! This category really doesn't have child categories.
		} else {
			// ohoho! ...but here are some. List them all...
?&gt;
			&lt;div class=&quot;box&quot;&gt;
			&lt;h1&gt;&lt;?php echo $categ_object-&gt;cat_name; ?&gt;&lt;/h1&gt;
			&lt;ul class=&quot;subnavigation&quot;&gt;
			&lt;?php wp_list_categories( 'title_li=&amp;depth=1&amp;child_of=' . (int)$categ_object-&gt;cat_ID ); ?&gt;
			&lt;/ul&gt;
			&lt;/div&gt;
&lt;?php
		}
	}
	// almost the same for page hierarchy.
	if( is_page() ) {
		// here we go...just do the same job
		$page_object = get_post( get_query_var( 'page' ), OBJECT );
		$list_subpages = wp_list_pages( 'title_li=&amp;depth=1&amp;echo=0&amp;child_of=' . (int)$page_object-&gt;ID );
		// wordpress never returns null or empty string. If children, &lt;a&gt; tag will be found, otherwise string is returned.
		preg_match_all( '|&lt;a.*?href=[\'&quot;](.*?)[\'&quot;].*?&gt;|i', $list_subpages, $ms );
		if( !$ms[ 1 ] ) {
			if( (int)$page_object-&gt;post_parent &gt; 0 ) {
				$parent_post_name = $wpdb-&gt;get_var( &quot;SELECT post_title FROM $wpdb-&gt;posts WHERE ID=&quot; . (int)$page_object-&gt;post_parent );
?&gt;
				&lt;div class=&quot;box&quot;&gt;
				&lt;h1&gt;&lt;?php echo $parent_post_name; ?&gt;&lt;/h1&gt;
				&lt;ul class=&quot;subnavigation&quot;&gt;
				&lt;?php wp_list_pages( 'title_li=&amp;depth=1&amp;child_of=' . (int)$page_object-&gt;post_parent ); ?&gt;
				&lt;/ul&gt;
				&lt;/div&gt;
&lt;?php
			}
		} else {
?&gt;
				&lt;div class=&quot;box&quot;&gt;
				&lt;h1&gt;&lt;?php echo $page_object-&gt;post_title; ?&gt;&lt;/h1&gt;
				&lt;ul class=&quot;subnavigation&quot;&gt;
				&lt;?php wp_list_pages( 'title_li=&amp;depth=1&amp;child_of=' . (int)$page_object-&gt;ID ); ?&gt;
				&lt;/ul&gt;
				&lt;/div&gt;
&lt;?php
		}
	}
?&gt;
</code>
</pre>
<p>
And this is it; save, and see how it works. You may want to replace style/class name for div in &#8216;navigation.php&#8217; but this should be an easy part.</p>
]]></content:encoded>
			<wfw:commentRss>http://rider.sofarider.com/blog/wordpress-tips/how-to-build-sequential-navigation-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
