Jump to content

Displaying only Subpages of Parent Pages - WP ?! Need Help!


MrBonsai

Recommended Posts

Hi Ppl,

 

i got a problem, i just can't get it working....

I have a sidebar which only appears if the page has subpages and it lists only direct ones.

So if I would have page1,page2,page3 with page3 only having subpages called subpage3a, subpage3b it seems working fine.

 

But with the code below I have 2 problems.

 

Problem 1: When clicked on a subpage the sidebar dissapears....that should not happen.

 

Problem 2: If I add Subpages to subpage3a f.e. then the menu stays the same and it does not display the childs of subpage3a, if I click on subpage3

 

I'm not a great coder, i put this together with snippets of code. So I hope someone could help me!

 

 

<?php

$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
if ($children) { ?>

<div class="sidebarwrap">

<?php
$title = get_the_title($post);
$parent_title = get_the_title($post->post_parent);

if(is_page()) { $check=$title.'.png'; };
if(file_exists(TEMPLATEPATH.'/images/'.$check)) { $image=$check; };
echo '<img src="'.get_bloginfo('template_url').'/images/'.$image.'" alt="" />'; ?>
<ul>
<?php if ( is_page() ) { ?>
<?php
if($post->post_parent)
$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&depth=1'); else
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
if ($children) { ?>

<?php echo $children; ?>

<?php } } ?>
</ul>
</div>
<?php } ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.