I use the following code to display a sub menu on each page that has sub pages. However, when I am on one of the child pages, the parent level seems to disappear, how can I keep the parentlevel while on a child page?
CODE:
<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=4");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=1&depth=4");
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
This is a picture to show how it looks when you are on a parent page with the sub menu open.
http://dev.worldwaterweek.org/wp-content/uploads/2009/08/on_parent_page.JPG
This picture shows how the sub menu displays while being on a child page, the parents are not visible.
http://dev.worldwaterweek.org/wp-content/uploads/2009/08/on_child_page.JPG
brettalton
Member
Posted 2 years ago #
I use this to show subpages of a parent page even while on a subpage. Maybe it will help
<?php
$subpages = (wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0')) ? wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0') : wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0') ;
if ($subpages)
{
?>
<h3>Sub-pages</h3>
<ul class="list-page">
<?php echo $subpages; ?>
</ul>
<?php
}
?>
brettalton
Member
Posted 2 years ago #
Sorry. That code is no good. I meant:
<?php
$subpages = ($post->post_parent) ? wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0') : wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0') ;
if ($subpages)
{
?>
<h3>Sub-pages</h3>
<ul class="list-page">
<?php echo $subpages; ?>
</ul>
<?php
}
?>
to show sub-pages of a parent page or while on a sub-page.
radiofranky
Member
Posted 2 years ago #
Hi,
I tried your code but it still display "child" in child page.
My structure is like this: catalog1 -> parent -> child
when I'm in child page, I would like to display list of parents(only, without any child) that are under catalog.
basically, when I'm in child page, I would like to go back two stage up and read parents that are under "catalog1".
your help is appreciated.
I am looking for something similar. I want to show child pages while on parent page and parent pages whil on child page. So far I have only managed to show child pages on parent pages and the extra code I added to show parents on child pages just shows all pages and child pages:
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
$parents = wp_list_pages('title_li=&depth=1'.$post->post_parent.'&echo=0');
if ($children) { ?>
<ul class="subpage-list">
<?php echo $children; ?>
</ul>
<?php }
elseif ($parents) { ?>
<ul class="parentpage-list">
<?php echo $parents; ?>
</ul>
<?php }
?>
Well, found a solution to show the sub page's parent page on the sub page and echo the child page list on the parent page:
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
$parent = get_the_title($post->post_parent);
if ($children) { ?>
<ul class="subpage-list">
<?php echo $children; ?>
</ul>
<?php }
elseif ($parent) { ?>
<ul class="parentpage-list">
<a href="<?php echo get_permalink($post->post_parent) ?>"><?php echo $parent;?></a>
</ul>
<?php }
?>
Will need to tweak the code some more, but this is what I was looking for more or less.
Had to make some adjustments to show parent page links only on subpages:
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<ul class="subpage-list">
<?php echo $children; ?>
</ul>
<?php } ?>
<?php
$parent = get_the_title($post->post_parent);
if (is_page() && $post->post_parent ) { ?>
Terug naar <a class="parentpage-list" href="<?php echo get_permalink($post->post_parent) ?>"><?php echo $parent;?></a>
<?php } ?>