Display subpages on your wordpress sidebar

November 1, 2008 · Print This Article

If you use pages and subpages on your blog, it can be a good idea to use your sidebar to create a menu of subpages. If you’d like to try, the following code is what you need!

In order to achieve this recipe, place the following code on your sidebar.php file.

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

The above code executes the wp_list_pages function, with the echo=0 parameter, which allow us to get the result of the function without displaying it. Then, we test if the $children variable isn’t empty, and we display our children pages.

Your choice for site templates and wordpress themes


Got something to say?

You must be logged in to post a comment.