This is just a quick and easy tip, but it was harder to find the answer to than I would have expected. (…or maybe I just didn't appease the Google Gods correctly when searching.)
If you have a page hierarchy within your WordPress site and you want to display (such as in the sidebar) the immediate children of the current page that you're on, here's the code to do it.
<?php
// will display the subpages of this top level page
$children = wp_list_pages("title_li=&child_of=" . $post->ID . "&echo=0");
if ($children)
{
// custom formatting goes here, just print
// $children when you want to render the link
echo '<div id="pagelist">' . "\n";
echo "<ul>\n$children\n</ul>\n";
echo '</div> <!-- end div id="pagelist" -->' . "\n";
} // end if test
?>
Please note that this method only lets you custom format the display around the actual link. wp_list_pages() will return the text with the anchor link already wrapped around it. I haven't dug into how to further format the link.
I hope that helps!
Comments
2 Responses to “WordPress – Displaying Custom-Formatted Links To Page Children”
John - Sunday, April 4th, 2010 at 8:36 am :
This dissapoingtingly has nothing to do at all with a convenient way to call your children…
admin - Sunday, April 4th, 2010 at 9:28 am :
John, your comments read almost exactly like spammers. It took me a minute to realize that they were your comments.
…and another minute to get the joke. ;o)
Leave a Reply
Social
Twitter Feed
Friends
About | Professional | Interests | Blog | RSS Feed
Copyright ©2010 Kenny Carlile. All rights reserved.