Benjash Twitters
Categories
- Crap (5)
- Dubai (1)
- Manchester (1)
- Music (1)
- Web Design (13)
Tags
Bay Central Canvas code CSS Cufon Developing Dubai Dubai Marina easing Flash Font Generator Font Replacement Free gallery Graphic Design Help Center Live htaccess images Indie Javascript jquery labourus Launch Site Live Support Chat Mac Manchester Music Northern Quarter Opensource PHP Portfolio Real Estate Website Select Property SEO SEO Freindly Sifr Skyscraper City snippet Text Typography W3C Web Standards Weird Wordpress Themes XHTMLArchives
Wordress sub-menu navigation
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 other issues:
- Finding out the depth of the page within the hierarchy of the site.
- Control over whether the menu displayed “sibling” links or “children” links.
A lot of the existing tutorials are great, but their implementation is very broad. The “wp_list_pages” 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 great tutorial by Jake Goldman talking about a hardly mentioned but great function, called “get_post_ancestors();”. This cool function will create an array of the current posts ancestors. Using this I expanded on Jake Goldman’s great article, adding a little more finite control over the submenu.
Page depth and sibling / child code for WordPress
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.
#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) <= 1) {
#Shallow Link Display Children
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
} elseif (count($post_ancestors) >= 2) {
#Deep Link Display Siblings or Section Links
$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&depth=1');
} elseif (is_page()) {
#Default Display Children
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
}
if ($children) {
#Outputs the submenu if it exists
echo('
- Sub Menu');
echo($children);
echo('
Example of the hierarchy of the site
Posted in Web Design | Tagged CMS, Functions, get_post_ancestors(), Navigation, PHP, Plugins, Section, Sibling, tutorial, WordPress, Wordpress Themes, wp_list_pages | Leave a comment
New Select Property website is live!
After a very busy month or so i’m happy to announce the launch of the new Select Property website. Specialising in property in Dubai and overseas investment properties.
This has been a massive project, mainly consolidating the thousands of pages the old SP site with the old Dubai Select site.
Our site is now powered by Wordpress and has over 2700 seo freindly, W3C validating pages.
Plus some annoying fireworks. At some point when have time I have will write a case study report on the project. For now just take a look.
Investment Property Abroad
Dubai Immobilien
Dubai Property