foreach($newsChildrenArray as $newsChildPage) {
//Test for an image on the current page
if($newsChildPage->images->eq(0) != null) {
//If this is the first article, make a larger image
if( $newsChildPage == $newsChildrenArray->first() ) {
$newsImg = $newsChildPage->images->first()->size(157,151);
}
else {
$newsImg = $newsChildPage->images->first()->size(77,71);
}
}
echo '
<a href="' . $newsChildPage->url . '">
<li '; if($newsChildPage == $newsChildrenArray->last())echo 'class="last"'; echo '>';
if($newsImg) {
echo '<img src="' . $newsImg->url . '" alt="' . $newsImg->description . '" />';
}
echo '
<p>
<span class="preview-title">' . $newsChildPage->title . '</span> • <span class="preview-date">' . $newsChildPage->date . '</span>
<br />' . $newsChildPage->summary . '
<a href="' . $newsChildPage->url . '" class="read-more">Read More...</a>
</p>
</li>
</a>
';
}
Unfortunately, ProcessWire chokes on the test. It echos the first element in the array correctly and then spits out "Fatal error: Nesting level too deep - recursive dependency?"
Strangely, it has no problem with the similar test I perform later on using last() to output a class on the last array element.
I created a simple workaround by adding a counter to the foreach loop and testing for the first element in the loop, but I'm curious--for future reference and a better understanding of the API--why this would be failing. Is there a better way of doing this that would still utilize the PW API?













