Jump to content

echo titles from child of child


webhoes
 Share

Recommended Posts

Hello,

I have a page that consists of the body of the page and the title and bodies of it's childpages with a foreach. That part works. Each childpage can have a sidebar if filled.

What I can't get done is getting the childpages of the childpages. I want the titles of those child/child pages in the sidebar of their parent.

 

main page           |sidebar

About (parent)    | no listing of Part 1 etc...

Part 1 (child)        |list childpages to Part 1 <- can't get this to work

Part 2 (child)         |list childpages to Part 2 <- can't get this to work

Part 3 (child)         |list childpages to Part 3 <- can't get this to work

 

This is my code so far... I tried several other options, but none got what I want. Can somebody give me a hint...

<div id='main'>

    <!-- main content -->
    <div id='content'>

        <h1><?php echo $title; ?></h1>

<?php // Primary content is the page's body copy
echo $page->body; ?>

<?php $this_page = $page->get(id);

// if the rootParent (section) page has more than 1 child, then render
// section navigation in the sidebar (see _func.php for renderNavTree).
if($page->rootParent->hasChildren > 1) {
    $sidebar = renderNavTree($page->rootParent, 3);
    // make any sidebar text appear after navigation
    $sidebar .= $page->sidebar;
} ?>
</div>
        <!-- sidebar content -->
        <?php if($sidebar): ?>

            <div id='sidebar'>

                <?php echo $sidebar; ?>

            </div>

        <?php endif; ?>



<?php foreach ($pages->get($this_page)->children as $child) {
  
    $image = $child->images->first();
    $image = $image->url;
?>

<div id="content" style="background: url('<?php echo $image; ?>') no-repeat center top;">
  <h1> <?php echo $child->title; ?></h1>
    <?php echo $child->body; ?>
    <?php if($sidebar): ?>

        <div id='sidebar'>
    <?php foreach ($child->child->children as $children2) {
        foreach ($children2->children as $child2) {
            echo "<h1>{$child2->url}</h1>";
        }
    }
    ?>
        </div>

    <?php endif; ?>
    </div>
<?php } //end childpage foreach ?>
</div>

 

 

 

Link to comment
Share on other sites

Hello @webhoes,

unless your child pages contain a page field called child, you don't need the second child property here:

foreach ($child->child->children as $children2) {
	foreach ($children2->children as $child2) {
		echo "<h1>{$child2->url}</h1>";
	}
}

Instead you can do it without it:

foreach ($page->children as $child) {
	echo $child->title;
	foreach ($child->children as $child2) {
		echo $child2->title;
		foreach ($child2->children as $child3) {
			// And so on...
		}
	}
}

Regards, Andreas

Link to comment
Share on other sites

Thanks @AndZyk,

If I am correct this is basicly the navtree.

I am looking for something dynamic. The page it belongs to should be seen as the 'root' page and only show the first line of childeren of that page.

Most of of those pages are in a foreach. In the frontpage of the site is every childpad is a new css row. So per row aka childpad I should only see the childeren for that childpage.

Hopefully I explain it clear enough...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...