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.

<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?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

Comments

Got something to say?

You must be logged in to post a comment.