Jump to content
webhoes

echo titles from child of child

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>

 

 

 

Share this post


Link to post
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

Share this post


Link to post
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...

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By louisstephens
      From my last post, I was given a good idea on how to count the repeater items, and it worked wonderfully. I got my code working well and the columns (based on the count) all work well as well. Now, I have a head scratcher on my hands. 
      <?php $buttonsIncluded = $page->special_custom_buttons->find('special_custom_buttons_include=1'); $buttonsIncludedCount = count($buttonsIncluded); $buttonsIncludedCountAdditional = $buttonsIncludedCount +1; echo $buttonsIncludedCount; ?> <div class="row"> <?php foreach($buttonsIncluded as $button): ?> <?php if($button->custom_buttons_include): ?> <?php if($buttonsIncludedCountAdditional == 2): ?> <div class="col-6"> <a href=""><?php echo $button->custom_buttons_text; ?></a> </div> <?php elseif($buttonsIncludedCountAdditional == 3): ?> <div class="col-4"> <a href=""><?php echo $button->custom_buttons_text; ?></a> </div> <?php elseif($buttonsIncludedCountAdditional == 4): ?> <div class="col-3"> <a href=""><?php echo $button->custom_buttons_text; ?></a> </div> <?php endif; ?> <?php endif; ?> <?php endforeach; ?> </div> All of this is included in a larger foreach statement that is pulling in other data (like body copy etc etc) from a Page Table field. As you can see in my code above, I am adding "1" to the count, so I can have space in the grid layout for a new button.
      So, right now: it looks something like: 
      [repeater button] [repeater button] [repeater button] [space for new button] What I really need to do is to pull in the button from the Page Table and add it into the new space so it looks like:
      [repeater button] [repeater button] [repeater button] [button from Page Table] Is this even possible todo, or is there a better way to go about this? 
       
      *Edit*
      So, I really just overlooked something quite easy here. Since the grid is based on 12 columns, I could just take 12 and divide by $buttonsIncludedCountAdditional which would give me the remaining col width to use outside the foreach loop. I was trying to make this too complicated.
    • By rolisx
      Hi all
      I have a problem here. I created a gallery with 240 pictures. Created an images field with no maximum amount (0). Unfortunately, only 98 of the 240 images show on the website. Any idea what I possibly could have done wrong? Thanks for your help!
      <?php foreach ($page->images as $image) { $options = array( 'quality' => 90, 'upscaling' => false ); $thumb = $image->size(250, 250, $options); ?> <div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 col-6 foto"> <a href="<?= $image->url ?>" data-lightbox="lightbox" > <img src="<?= $thumb->url ?>" alt="" > </a> </div> <?php } ?>  
    • By celfred
      Hello !
      I have somehting I don't understand here... Here's my code :
      $allPlayers = $pages->find("parent.name=players, team=$selectedTeam"); $allTrains = $allPlayers->find("template=event, task.name~=ut-action, refPage!='', date>=$startDate, date<=$endDate, sort=refPage, sort=date"); bd('$allTrains:'.$allTrains->count()); // DISPLAYS 0 ???? foreach($allPlayers as $p) { $allTrainings = $p->find("template=event, task.name~=ut-action, refPage!='', date>=$startDate, date<=$endDate, sort=refPage, sort=date"); $test += $allTrainings->count(); } bd('$test:'.$test); // DISPLAYS 883 pages (normal) As you can read from my comments, I have no idea why my first $allTrains stays at 0 while the second request actually finds the corresponding pages. If someone could explain I'd appreciate a lot. I have been struggling with this for hours now... For your information, my pages having template 'event' are in a subtree like so :
      - player 01
        - history-1
          - event 01
         - event 02
         - event ...
        - history-2
          - event 01
          - event ...
      - player 02
        - history-1
          - event 01
         - event 02
         - event ...
        - history-2
          - event 01
          - event ...
      - player ...
        - history-1
          - event 01
         - event 02
         - event ...
        - history-2
          - event 01
          - event ...
       
      Thanks in advance. (sorry for my preceding 'tree' which doesn't look like much. I need to find a way to output this better 😉 )
    • By Noel Boss
      EDIT:
      What I'm actually really looking for is a way to edit and add children of a page in a similar way as RepeaterMatrix fields:
      Easy to add new ones and easy to move, hide and modify inline:

      ––––
      I have a problem and am so close to a solution, but everything i've found so far only gets me about 95% and before I create something on my own want to ask is anyone knows a soltion or if I miss something.
      My simple requirement: Editing Children and creating new ones inside the current parent page context – eighter inline or in a Lightbox.
       
      Not working Option A:
      With page relation fields I can create new pages – but it requires me to select a fixed parent. If I don't provide a parent, no new link is present.

      Not working Option B:
      With the awesome AdminPageFieldEditLinks Module I can create new Pages directly without the need to provide a parant beforehand – but then I need to select it at runtime.

      There is a new link now – the link is: parent_id=0&amp;template_id=51&amp;modal=1 … if it only provided the correct parent_id!!!

      But now i have to select the parent:

      Not working Option C :
      That's what I do right now… Reordering the Child-Field to the first tab – but to maintain the context, I would need the edit and new button to open a lightbox instead of a page reload.
       
      Possible solutions:
      For A+B: If I could provide a selector as parent, this would solve my issue: "parent=page.id" or a checkbox "use parent page for new pages". Or I could use some hook?
      For C : I could write my own javascript to open the links in a Lightbox.
       
    • By burning
      Hi All, maybe a really stupid question, but is there a way to sort repeater items on -created?
      Like $page->social_activity('limit=10,sort=created'), with 'social_activity' as the repeater field?
      Tried this but it didnt work 😞 
      Any help appreciated! 
×
×
  • Create New...