Viewing 6 replies - 1 through 6 (of 6 total)
  • 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
    	}
    ?>

    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.

    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 } ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show parent while on child page’ is closed to new replies.