Jump to content

Children and children of children ?


ank
 Share

Recommended Posts

Hey,

i'm just started with Processwire, followed the tutorials and every basic thing i try seems to work, better than i expected.

I already love Processwire and it's many possibilities.

But now i have a very complicated (althrough for a beginner) situation.

I want to get te children of a page (exist only out an image and title) and under the title and image of the children the titles and urls of the children of these children:

Page

  Child 1 - Title - Image

    Child 1 of Child 1 - Title -Url

    Child 2 of Child 1 - Title -Url

    Child 3 of Child 1 - Title -Url

  Child 2 - Title - Image

    Child 1 of Child 2 - Title -Url

    Child 2 of Child 2 - Title -Url

    Child 3 of Child 2 - Title -Url

  Child 3 - Title - Image

    Child 1 of Child 3 - Title -Url

I tried many diffrent ways, but it does not work at all! (i just get nothing on the page)

Its getting to difficult for me as a beginner, i ended up with the following code:

     <?php
        $pagename = $page->child->title;
          foreach($page->children as $headimage) {
            $thumb = $headimage->size(600, 400);
            $pagename = $page->child->title;
            echo "<div class='section'>";
              echo "<a href='$page->child->url'>";
                echo "<div class='sectionimage'>";  
                  echo "<div class='image'>";
                    echo "<img src='$thumb->url' alt='$headimage->description'></img>";
                  echo "</div>";
                  echo "<div class='caption'>";
                    echo "<p>'$page->$child->title'</p>";
                  echo "</div>";
                echo "</div>";
              echo "</a";
              echo "<div class='brands'>";
                echo "<ul>";
                  foreach($page->children->children as $childchild) {
                    echo "<li><a href='$childchild->url'>'$childchild->title'</a></li>";
                  }
                echo "</ul>";
              echo "</div>";
            echo "</div>";
          }
      ?>

what am i doing wrong ?

thanks.

Link to comment
Share on other sites

Hi ank and welcome to the forums.

Hard to know exactly how you have things set up, but give this a go. It's untested, so there might be something slightly amiss, but should be close:

<?php
$pagename = $page->child->title;
  foreach($page->children as $child) {
    $headimage = $child->headimage->first();
    $thumb = $headimage->size(600, 400);
    $pagename = $child->title;
    echo "
    <div class='section'>
      <a href='{$child->url}'>
        <div class='sectionimage'>  
          <div class='image'>
            <img src='{$thumb->url}' alt='{$headimage->description}'></img>
          </div>
          <div class='caption'>
            <p>{$child->title}</p>
          </div>
        </div>
      </a>
      <div class='brands'>
        <ul>";
        foreach($child->children as $childchild) {
          echo "<li><a href='{$childchild->url}'>{$childchild->title}</a></li>";
        }
        echo "</ul>
      </div>
    </div>";
  }

Sorry for getting rid of all your echo statements - they were driving me crazy :)

  • Like 2
Link to comment
Share on other sites

Not sure what you mean about the last rule not working. 

Leaving off the closing ?> in php is recommended when the entire file is php. I am sure there are more complete explanations out there, but take a read of this one:

http://developer.sugarcrm.com/2011/05/06/why-we-dont-using-closing-php-tags/

However it looks like you are swapping in and out of html / php, so you will need to close the tags in this case.

Link to comment
Share on other sites

I meant not leaving off te closing ?> but in the code suggested there was just a "?" missing before ">" on the last rule, which causes errors in the output.

It was just a type error i think.

Thank you so much for your help !

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