EyeDentify Posted May 24, 2016 Share Posted May 24, 2016 Hello There fellow PW users.I have been racking my brain looking at this code for a while know and the solution probably is simple.But i need a fresch set of eyes on my problem.I have this code: <?PHP /* render siblings or not */ $sibItems = $page->siblings(); if(count($sibItems) > 0) { echo('<ul class="unstyled-list">'); echo('<li>Other post like this:</li>'); /* render the siblings if any, exclude current page */ foreach($page->siblings('limit=5', false) AS $sibling) { echo("<li><a href=\"{$sibling->url}\">{$sibling->title}</a></li>"); } echo('</ul>'); } ?> What i am trying to do is detect if there are any siblings to the current post, and if there are siblings then render them. If no siblings then not render. You get the picture.But at this point the IF statement is run no mather what i do. and this post i am testing on has no siblings. It is a lone child under another page so it should not have siblings.But the count() method gets a 1 integer anyway ?So what am i doing wrong here?I thought it should give me a 0 integer if there are no siblings.Maybe i have forgotten something.Thanks for all your help. Link to comment Share on other sites More sharing options...
onjegolders Posted May 24, 2016 Share Posted May 24, 2016 I think page->siblings() returns the current page as well (not sure why) So may have to do something like this (untested) <?php $siblings = $page->siblings()->remove($page); ?> 1 Link to comment Share on other sites More sharing options...
EyeDentify Posted May 24, 2016 Author Share Posted May 24, 2016 (edited) I think page->siblings() returns the current page as well (not sure why) So may have to do something like this (untested) <?php $siblings = $page->siblings()->remove($page); ?> You are absolutly right... but it is the default behavior of siblings() to return current page. I have to specify "false" to make it not do that. I missed it. Thank you for your catch https://processwire.com/api/ref/page/siblings/ I think you gave me the way to a solution. solution: <?PHP $sibItems = $page->siblings(false); ?> And now it works as i expected Edited May 24, 2016 by EyeDentify 1 Link to comment Share on other sites More sharing options...
onjegolders Posted May 24, 2016 Share Posted May 24, 2016 Pleased to hear it! (Didn't know about false, thanks). 1 Link to comment Share on other sites More sharing options...
EyeDentify Posted May 24, 2016 Author Share Posted May 24, 2016 Pleased to hear it! (Didn't know about false, thanks). No problem sir. We are all here to help each other if we can. Link to comment Share on other sites More sharing options...
Soma Posted May 24, 2016 Share Posted May 24, 2016 Alternatevely if($page->parent->numChildren(true) > 1){ // true = only visible ones } This doesn't load the children/siblings pages just count. 4 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now