• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

Wordpress Custom Sidebar Sub-navigation

Hey there!

I am creating a custom Wordpress theme for a site I'm developing and want to add a sub-navigation menu to the sidebar.

So how it will work, once you are on a particular page, if the page has "child" pages, it will post the parent page as a title and the child pages in an unordered list. So something like this:

<h3>Parent Page</h3>
<li>Child Page 1</li>
<li>Child Page 2</li>
<li>Child Page 3</li>

Open in new window

If a page doesn't have any child pages, I don't want it to show anything.

Can someone lend me a hand? I've found a couple of samples online but none that are exactly what I'm looking for.


P.S. I would prefer to not use a plugin to do this.
  • 2
1 Solution
AdamAuthor Commented:
I think I answered my own question :)

   $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<?php $parent_title = get_the_title($post->post_parent);
echo $parent_title; ?>
<?php echo $children; ?>

Open in new window

AdamAuthor Commented:
I did a little more sleuthing on my own and discovered a solution. No need for experts! :)
Jason C. LevineNo oneCommented:
Good work, furio13!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now