If you’ve been following the recent trends with premium WordPress themes, you’ve probably noticed that the two-tiered navigation menu has become extremely popular. An example of this is the popular Revolution WordPress themes. This style of menu can be used in a variety of ways, but the most common seems to be to display your children pages in a menu below your blog’s parent pages.

If you’ve wondered how to hack your existing WordPress theme to accomplish something along these lines, Darren Hoyt has taken the time to explain this in his post Creating Two-Tiered Conditional Navigation in WordPress. Here is the PHP you’ll need:

<ul id="nav">
<?php wp_list_pages('title_li=&depth=1'); ?>
</ul>
<?php if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul id="subnav">
<?php echo $children; ?>
</ul>
<?php } else { ?>
<?php } ?>

Once you’ve got the code in place, you’ll want to style it to look the way you want it to. Click over to Darren’s post to get the styling information!

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

There Are 3 Responses So Far. »

  1. 1 Fernando
    Wednesday, March 12th, 2008 at 6:04 am

    Nice hack, I’ll traslate the tip in my blog ;)

  2. 2 jbj
    Wednesday, March 12th, 2008 at 4:42 pm

    Thank you for the tip!
    If anyone is interested, I wrote a similar article for creating à dropdown menu for categories/sub-categories.
    The article is in French and can be read here.



Leave A Comment