Solved

Wordpress Custom Sidebar Sub-navigation

Posted on 2011-03-15
3
494 Views
Last Modified: 2012-05-11
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>
<ul>
<li>Child Page 1</li>
<li>Child Page 2</li>
<li>Child Page 3</li>
</ul>

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.

Thanks.

P.S. I would prefer to not use a plugin to do this.
0
Comment
Question by:Adam
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
Adam earned 0 total points
ID: 35139584
I think I answered my own question :)

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

Open in new window

0
 
LVL 1

Author Closing Comment

by:Adam
ID: 35139589
I did a little more sleuthing on my own and discovered a solution. No need for experts! :)
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 35140022
Good work, furio13!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question