• Good afternoon all.

    I have a slight problem with one of my “Page” templates. I am creating a site in WordPress with the intention of using it for its CMS rather than blogging needs. I will not need to use posts and the whole site will be made using pages.

    That being said the pages are grouped into parents and children. so for example i have:
    – About Us (parent)
    – Vision, Mission and Values (child)
    – Contact Us (child)
    – Careers & Employability Staff (child)

    As part of a custom page template i have created there is a section on the left that displays the child pages. This works fine when viewing the About Us page and the links work correctly navigating you to the child page. However when you then go on that child page the list disappears as i would expect because they have no children they are the children.

    What i need is to modify my code to display the fellow children. My code looks like this

    <div id="leftNavContainer">
    	<?php
    		$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    		if ($children) { ?>
    		<div class="leftNavInnerContainerHeader"><?php echo get_the_title($ID); ?> </div>
    			<div id="leftNavInnerContainerBody">
    				<ul>
    					<?php echo $children; ?>
    				</ul>
    			</div>
    		<?php } ?>
    </div>

    I hope i have explained myself well enough

    Any help would be thankful

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try this code:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Thread Starter Hoppo

    (@hoppo)

    Thanks for that, i got that working a treat. My problem now comes thou when i want to display a child of a child :p

    The screenshot here shows what my navigation needs to look like
    Image

    As the image shows “Student, Gradudates and Postgraduates” is the parent link, and the child links are all shown below.

    My problem now thou is that “Postgraduates” has children of its own. These children should only be shown when the parent is active in this case “postgraduates”. There are a number of places where this will be needed. For example the “employability” page also has this.

    The code that i am using at the moment is
    Pastebin

    I suppose i need to include another IF statement in there somewhere, but am unsure on what to do.

    Any help would be great !

    Thanks

    David

    Not sure if I understood you correctly, but try this.

    if ( count($post->ancestors) < 1 ) {
        $args = 'depth=1&child_of=' . $post->ID;
    } else {
        $args = 'depth=1&child_of=' . $post->post_parent;
    }
    wp_list_pages($args);

    Thread Starter Hoppo

    (@hoppo)

    Hi thanks for the reply, but i cant seem to get that code you provided me to work. All i want to do is replicate the menu as that was in the screenshot in my previous post.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display a parents children works but problem when viewing a child page’ is closed to new replies.