Getting siblings children fields not working

I have a section of my website where I am trying to get the URL of the listed sibling page however it is linking to my sibling’s child. The same button I am trying to only display if there are more than 3 children in the listed sibling.

<?php foreach ($page->siblings()->listed() as $project): ?>
<h2>
    <?= $project->title() ?>
</h2>
<?php foreach ($project->children()->limit(3) as $project): ?>
    <div class=" background-image" style="background-image:url(<?= ($f = $project->image()) ? $f->url() : ''; ?>)">
    </div>
<?php endforeach?>
<?php if ($page->siblings()->count() > 3):?>
    <a href="<?= $project->url() ?>" >
        See More
    </a> 
<?php endif ?>
<?php endforeach?>

I guess there is a typo, you should $project variable:

Use:

<?php if ($project->siblings()->count() > 3):?>

Instead

<?php if ($page->siblings()->count() > 3):?>
1 Like

Ahh yea this makes sence thanks boss. Any advice with the url, it takes me through to the projects first child? Where I am trying to take it just to the project itself (sibling)

Change variable in second loop, for example use $child to avoid conflict.

<?php foreach ($project->children()->limit(3) as $child): ?>
1 Like

thank you so much, yea i guess labling the variable in the second loop the same is where the issue is. :heart: :heart: :heart: :heart: