Blog

FreshBooks

How to create a sidebar navigation in WordPress

Here’s a snippet that will give you an instant sidebar navigation in WordPress. It grabs the post parent title and the children of that parent.

<div id="sidebar-nav">
< ?php if($post->post_parent) { ?>
< ?php $parent_title = get_the_title($post->post_parent); ?>
< ?php $permalink = get_permalink($post->post_parent); ?>
<h3><a href="<?php echo $permalink; ?>" title="< ?php echo $parent_title; ?>">< ?php echo $parent_title; ?></a></h3>
 < ?php } else { ?>
<h3><a href="<?php echo get_permalink(); ?>" title="< ?php echo $parent_title; ?>">< ?php the_title(); ?></a></h3>
< ?php } ?> 
 
< ?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>
< ?php echo $children; ?>
</ul>
< ?php } ?>
</div>

Related posts:

  1. How to create a CSS3 border fadeout
  2. How to create a custom Apple iPad/iPhone Home screen icon for your Website
  3. Working with WordPress child themes: Including files and getting the theme path

One Response to “How to create a sidebar navigation in WordPress”

  1. Prasad Says:

    Nice Article.

    Once visit http://www.wordpressstop.com here you will find lot of articles regarding to WordPress.

    keep Smiling

Comment on this article: