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!
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.
Credit goes to Kyle Eslick and his awesome blog wphacks.com for this excellent recipe!
20 Responses
Hi Jean,
thanks for recipe..
is it possible to show your recipes’ demos or screenshots in a specific page or here?
so let us know what we will see before applying code..
Cheers~
I’d love to upload exemples for my recipes, but sadly it will probably take too much time and I got 2 other blogs, so if I want to continue to publish one recipe per day, I don’t think I’ll be able to do this
ok,you r right Jean,
i prefer one recipe per day:)
take it easy
cheers~
Thats called remix recipe.
Bcoz we are reconstructing our blog using these subpages links
yeah right maintaining many blogs is consuming time …
once again, add some screenshot brother
byme
Trues why dont you put some pictures???
@byme & Evan: As I said, I don’t have enought time to upload exemple or screenshots of recipes, unless it is necessary.
However, I keep your suggestion in mind, maybe I’ll do that later
The if statement’s not really that necessary - if no subpages exist, you’ll just have an empty unordered list. But I suppose it is a bit cleaner.
Thanks for this code, it works great and is self explanatory. Why is a screenshot needed?
Question: Would it be possible to have WP sidebar always display all subpages, regardless of the main page?
I agree about adding some picture and make us see how it looks when we implement this code.
This is a nice simple solution - one thing I noticed is that if the child page has subpages they display also.
I wonder if it’s possible to limit it to immediate children only?
I’ve added the code to my Sidebar.php and It doesn’t return anything. I see nothing on my page.
Trackbacks: