Jump to content

Siblings selector


Peter Knight
 Share

Recommended Posts

Was browsing the cheatsheet trying to pickup some new selector tricks and noticed the next all siblings selector.

$page->nextAll($selector, $siblings)

Introduced in Version 2.0

Description

Return all sibling pages after this one, optionally matching a selector. $selector Optional selector string. When specified, will filter the found siblings. $siblings Optional siblings to use instead of the default.
 

Based on the description above, should the following not return a pages siblings?


<?php			
$solutions = $page->nextAll($siblings);
foreach ($siblings as $solution){
echo "
<a href='{$solution->url}'>{$solution->title}</a>
";}
?>

It works if I drop the nextall and refer to siblings without the variable $

<?php
$solutions = $page->siblings;
foreach ($solutions as $solution){
echo "
<a href='{$solution->url}'>{$solution->title}</a>
";}
?>

Just curious really. 

Link to comment
Share on other sites

Just curious really. 

Not curious at all. You didn't define the variable $siblings.

$siblings in the description is meant as the 2nd optional argument in the method nextAll().

If you call the function $page->nextAll() you don't need to set an Argument. Both are optional.

If you like to specify one or two Arguments, you should define them.

First or single Argument should be a selector string.

Second one should be a PageArray. If you want to set only the second Argument you have to set an empty string as first Argument.

This should work:

<?php
$siblings = $pages->find('parent=1');      
$solutions = $page->nextAll('',$siblings);
foreach ($solutions as $solution) {
    echo "<a href='{$solution->url}'>{$solution->title}</a>";
}
?>
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...