Posts tagged subpage
Page and Sub-page Menus In WordPress
2Recently I wanted to change the theme I use on my personal blog to the following: http://www.wpdesigner.com/2007/01/22/digg-3-columns-wordpress-theme/ as the current one I was using was pretty awful (to say the least) and this was a lot better
I liked this theme but unfortunately it lacked one thing (as do a lot of other themes I've used) - an auto generating set of page menu tabs at the top. The default theme just had a link to the home and about pages, so I added this in and it now works exactly the way I wanted it to. I've pasted the code below should you wish to do something similar.
This mod basically creates a list of all the parent pages along the top (which are rendered as tabs due to the css), and then when a link of a parent page is clicked, it displays the home tab, the tab for the parent page and then the list of tabs for the sub pages of that parent page.
On my site so far I only have one level of sub pages below the parent, but I believe this should work for any hierarchy of sub-sub pages - if you use this code and it does please post a comment to let me know.
Also this is a bit rough - the next time I use it I will probably clean it up a bit, but I know it works for now. If you'd like to provide me with a cleaner version before I have chance to work on it please feel free to drop me a line, and if it works I'll also post it here.
1,
'show_date' => '',
'date_format' => get_option('date_format'),
'child_of' => 0,
'exclude' => '2, 53',
'title_li' => '',
'echo' => 1,
'authors' => '',
'sort_column' => 'menu_order, post_title');
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)
{
if(intval($post->post_parent)>0)
{
wp_list_pages('title_li=&include='.$post->post_parent);
}
else
{
?>