Handling Nested Menus in WordPress

[bhtweetthis]

As you most probably have noticed that I am using WordPress more and more these day, becuase it is so easy to customise and make it do almost anything you want.

But one of the things that WordPress lacks (in its native format), is a way to handle menus.

The only way menus are made is by creating a heirarchical structure of pages. This is fine if every page has content on it, but what if you need to create a page that is just a placeholder for the child pages.
And when a user clicks on the placeholder page, you usually want it to go directly to the first child page.

nested-menuOn a recent site that I created (see image below) , I had a menu item called "Services", that was just a placeholder for the child pages.

So when someone clicked on the "Services" page, I wanted then to immediately go to the first child page. In this case its "Price List"

So how do you make this happen ?

Actually it very easy..

The trick, if you can call that is to create a new template page that only these placceholder pages will use.

Copy the following PHP code, and paste into Notepad and save as "gotofirstkid.php"

<?php
/* Template Name: Go to first child */

$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
if ($pagekids) {
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
} else {
// Do whatever templating you want as a fall-back.
}
?>

FTP the file up into your theme's directory, and go back into the WP admin area and then, for each placeholder page select the template called "Go To First Child".

Its done!

Now whenever someone clicks on a placeholder page, its gets taken to the first child page. So using the example shown in the image above, is someone clicks on the "Services" item, they are immediately taken to the "Price List" page.

Let me know if this helps you out at all.

I found this technique on the wordpress forum all thanks go to the orginal poster.

[bhtweetthis]

Note that a pronoun can also be the object of a www.eduessayhelper.org preposition?