<?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>Benjamin Ashcroft &#187; CMS</title>
	<atom:link href="http://www.benjaminashcroft.com/tag/cms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.benjaminashcroft.com</link>
	<description>Manchester based web developer and designer of high quality websites, printed matter and moving images.</description>
	<lastBuildDate>Tue, 17 Aug 2010 12:19:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Wordress sub-menu navigation</title>
		<link>http://www.benjaminashcroft.com/web-design/wordress-sub-menu-navigation/.</link>
		<comments>http://www.benjaminashcroft.com/web-design/wordress-sub-menu-navigation/.#comments</comments>
		<pubDate>Tue, 08 Sep 2009 16:29:00 +0000</pubDate>
		<dc:creator>Benjash</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[get_post_ancestors()]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Section]]></category>
		<category><![CDATA[Sibling]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Wordpress Themes]]></category>
		<category><![CDATA[wp_list_pages]]></category>

		<guid isPermaLink="false">http://www.benjaminashcroft.com/?p=153</guid>
		<description><![CDATA[Been developing a solution for a new corporate site in development. Utilizing WordPress as a fully blown CMS, a major priority was developing a dynamic sub navigation solution within the theme. I found loads of sub menu and section navigation plug-ins but there where all a little too complicated. Additionally I came up against two [...]]]></description>
			<content:encoded><![CDATA[<p>Been developing a solution for a new corporate site in development. Utilizing WordPress as a fully blown CMS, a major priority was developing a dynamic sub navigation solution within the theme. I found loads of sub menu and section navigation plug-ins but there where all a little too complicated.</p>
<p>Additionally I came up against two other issues:</p>
<ol>
<li>Finding out the depth of the page within the hierarchy of the site.</li>
<li>Control over whether the menu displayed  &#8220;sibling&#8221; links or &#8220;children&#8221; links.</li>
</ol>
<p>A lot of the existing tutorials are great, but their implementation is very broad. The <strong>&#8220;wp_list_pages&#8221;</strong> function within WordPress is great, very flexible and well documented. Yet swapping between section or child menu based on page depth seemed to be a dead end. Until I read this <a href="http://www.cmurrayconsulting.com/wordpress-tips/current-section-navigation-wordpress/">great tutorial by </a><a title="Posts by Jake Goldman" href="http://www.cmurrayconsulting.com/author/jgoldman/">Jake Goldman</a> talking about a hardly mentioned but great function, called <strong>&#8220;get_post_ancestors();&#8221;.</strong> This cool function will create an array of the current posts ancestors. Using this I expanded on Jake Goldman&#8217;s great article, adding a little more finite control over the submenu.</p>
<h2>Page depth and sibling / child code for WordPress</h2>
<p>Heres the PHP code I dropped into the sidebar.php of my WordPress theme. Hopefully should be of use. My example displays the sibling/ section links into the navigation. While displaying the child links for all the pages higher in the hiarachy.  Hope this code is usefull.</p>
<pre name="code" class="php">

#Creates Array from the pages ancestors post ID's
$post_ancestors = get_post_ancestors($post);

#Un-comment array for guidence
#print_r($post_ancestors);

#Gets the base post id
$top_page = array_pop($post_ancestors);

#Get post depth
#After a certain depth into the page hierarchy the page displays sibling menu items in sub menu.

if (count($post_ancestors) &lt;= 1) {
#Shallow Link Display Children
$children = wp_list_pages('title_li=&amp;child_of='.$post-&gt;ID.'&amp;echo=0&amp;depth=1');

 } elseif (count($post_ancestors) &gt;= 2) {

#Deep Link Display Siblings or Section Links
$children = wp_list_pages('title_li=&amp;child_of='.$post-&gt;post_parent.'&amp;echo=0&amp;depth=1');

} elseif (is_page()) {

#Default Display Children
$children = wp_list_pages('title_li=&amp;child_of='.$post-&gt;ID.'&amp;echo=0&amp;depth=1');

} 

if ($children) {
#Outputs the submenu if it exists
echo('
<ul>Sub Menu');
echo($children);
echo('</ul>

');
</pre>
<h3>Example of the hierarchy of the site</h3>
<ul><a class="post-edit-link" title="Edit post" href="http://ved.selectproperty.com/wp-admin/page.php?action=edit&amp;post=495"></a></p>
<li class="page_item page-item-489 current_page_ancestor current_page_parent">Locations
<ul>
<li class="page_item page-item-490">Manchester</li>
<li class="page_item page-item-497">Dubai</li>
<li class="page_item page-item-499">Turkey</li>
<li class="page_item page-item-495 current_page_item">Dubai Marina
<ul>
<li class="page_item page-item-534">Botanica</li>
<li class="page_item page-item-511">The Torch
<ul>
<li class="page_item page-item-516">Overview</li>
<li class="page_item page-item-518">Facilities</li>
<li class="page_item page-item-520">Properties
<ul>
<li class="page_item page-item-524">2 Bedroom Apartment</li>
</ul>
</li>
<li class="page_item page-item-522">Payment Plans</li>
<li class="page_item page-item-527">FAQ’s</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.benjaminashcroft.com/web-design/wordress-sub-menu-navigation/./feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
