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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.