Topic: Cannot find children pages

I have 2 snippiets of code that rely on children() and neither of them work. All the content is there and published, and I can access the pages directly. But there seems to be something up with crawling my page tree.

First one (almost exact copy of one of the wiki examples):

<?php foreach($this->find('/')->children() as $menu): ?>
      <li><?php echo $menu->link($menu->title, (in_array($menu->slug, explode('/', $this->url)) ? ' class="current"': null)); ?></li>
<?php endforeach; ?> 

Second one:

<?php
$work_items = $this->children();

    foreach ($work_items as $item): ?>
        <h2><?php echo $item->title(); ?></h2>
        <div class="entry">
            <?php echo $item->content(); ?>
            <?php if ($item->hasContent('extended')) echo $item->content('extended'); ?>
        </div>
<?php
    endforeach; 
?>

I double checked my database, and the page structures are setup correctly. But I appear to get no children. Nothing gets printed from either of those loops. I know the scripts work because I took them from the published version of my site, while these issues are on my local server.

Thoughts anyone?

Thumbs up

2

Re: Cannot find children pages

MishieMoo wrote:

Thoughts anyone?

Two quick thoughts come to mind:

(1) You haven't said where in your page structure these "children" are - are both snippets looking for children of "root"? or further down the page tree? If the latter, your code will need adjusting.

(2) Where are you calling the snippets? If it's on a page, then "$this->" will mean that page. If it's in the Layout, then it refers to whatever page is currently displayed. More in the wiki.

If neither of these spark anything, then perhaps you could tell us more about the page structure, and where you're calling the snippets.

Re: Cannot find children pages

1. They are direct children. As I said, I have the exact same structure and content as on my site in production where the code snippets work. I am trying to get my local server to match the live site.

2. I am calling those snippets on the pages that have children. They are 100% in the correct spots because I have this code working on my live site.

But since you don't believe me that my tree is correct here's a diagram:
- Home Page
    - About me
    - Work
        - Item 1
        - Item 2

The first snippet, for the navigation, is called on the Home Page, and should display About Me and Work. Neither display.

The second code snippet is supposed to iterate over my work items and is called on the Work page.

The issue is not with my structure or where I'm calling these snippets.

Thumbs up

Re: Cannot find children pages

Mmhh, check the child pages 'Status'?

Thumbs up

Re: Cannot find children pages

All are published. I even went to the db to confirm it in case there was something funky going on.

Thumbs up

Re: Cannot find children pages

Perhaps this a stupid idea that you have already checked... but are you sure that both the snippet's and page's filters are set to '--none--'?

Visitors plugin on the forum | repository
SEO plugin on the forum | repository

Re: Cannot find children pages

Yep. I've never used filters.

Thumbs up

8

Re: Cannot find children pages

But Mishie - I believe everything you say! big_smile Just trying to think diagnostic type thoughts, is all...

MishieMoo wrote:

2. I am calling those snippets on the pages that have children. They are 100% in the correct spots because I have this code working on my live site.

So just to cross things off - could you try calling the snippets in the layout and see if they work? (This could dovetail with NicNLD's point about whether a filter is messing with your PHP, of course.)

[Update: or not dovetail, as the case may be... hmm ]

Last edited by David (2012-01-06 18:02)

Re: Cannot find children pages

You have DEBUG set to true (config.php) and yet nothing prints out?

Try/check a few options:

Check the snippets names match the argument in

$this->includeSnippet('snippet_name')

Could you try using the children function with the following arguments:

->children(null, array(), true)

For the menu snippet, you could try with:

<?php
    $root = Page::findByUri('/');
    foreach($root->children() as $menu): ?>
        <li><?php echo $menu->link($menu->title, (in_array($menu->slug, explode('/', $this->url)) ? ' class="current"': null)); ?></li>
<?php endforeach; ?>

Thumbs up

Re: Cannot find children pages

David, calling the snippets also do not work in the layout. That doesn't make sense. Everything's there...but the snippets just aren't getting anything.

Thanks for the tips andrewmman, but none of those work.

I changed the header script to your suggestion, still nothing.

Turning debug on also hasn't done anything.

Thumbs up

Re: Cannot find children pages

Okay so here's a weird side effect. Every time I save a post it decides that it needs to be archived. I don't change it but it becomes archived anyways?

Thumbs up

Re: Cannot find children pages

Hmm... sounds like something elemental is going wrong during storing of the article... What PHP and DB versions are you using?

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

13

Re: Cannot find children pages

mvdkleijn wrote:

Hmm... sounds like something elemental is going wrong during storing of the article... What PHP and DB versions are you using?

And I don't think we've even asked yet (for shame! ... unless I've missed it) what you're using for your localhost setup. There have been some glitches with MAMP, although I've been using XAMPP for years on a variety of machines and OS's with never a cloud in the skies.

Re: Cannot find children pages

Sounds a lot like this.

Everytime you update a page, if the 'valid until date' value is lower than the current time, it will automatically change the page status to 'Archived'. Doesn't matter if you try setting the status to 'Published' you need to either reset the 'valid until date' field or set it to another value, that is if you want to implement it.

Thumbs up

Re: Cannot find children pages

Thanks @andrewmman! That archive issue does appear to have fixed the problem.

Thumbs up