Roych Posted July 26, 2022 Share Posted July 26, 2022 Hello, I need some help with somethin Im working on. I want to show different design if the current page doesn't have siblings or children. I'm using basic-page template for all my articles (siblings, children and normal pages all with the same fields) and Im showing sidebar with siblings or children on all of them. But when the page doesn't have any of them I want it to be without the sidebar. I tried with: <?php namespace ProcessWire;?> <?php $nosidebar = $page->hasChildren() ;?> CODE WITH SIDEBAR <?php elseif ($page->siblings()) :?> CODE WITH SIDEBAR <?php elseif (!$nosidebar) :?> CODE WITHOUT SIDEBAR <?php endif ;?> It kinda works as it should but it shows shows me the sidebar on a page without children or siblings. Tried everything and got kind a lost here. Not even sure if this is the right way to do this. Any help greatly appreciated. Thank you R Link to comment Share on other sites More sharing options...
zoeck Posted July 26, 2022 Share Posted July 26, 2022 <?php namespace ProcessWire; $showsidebar = 0; // Set $showsidebar to 1 if the page has children or siblings if($page->hasChildren() || count($page->siblings(false))) $showsidebar = 1; if($showsidebar) { // Code with Sidebar } else { // Code without Sidebar } I think this should work, untested ? 1 Link to comment Share on other sites More sharing options...
Roych Posted July 26, 2022 Author Share Posted July 26, 2022 thank you for anwser I's not working as it should. I'll try to be more clear what I need. My tree menu looks like this: (messy I know) Articles (all below have "basic-page" template)- Page (should have sidebar with siblings)- Page (should have sidebar with siblings and children)-- Page (should have sidebar with siblings)-- Page (should have sidebar with siblings and children)--- Page (should have sidebar with siblings)--- Page (should have sidebar with siblings and children)---- Page (should be full width)Page (should be full width)Page ( should be full width)Page ( should have sidebar with siblings or children)- Page (should be full width) So if there is page a page on it's own it should also be without sidebar. I hope you understand what I need. Thank you very much R Link to comment Share on other sites More sharing options...
Gideon So Posted July 27, 2022 Share Posted July 27, 2022 Hi @Roych You may need $page->next() https://processwire.com/api/ref/page/next/ if($page->next()->id) { // Code with Sidebar } else { // Code without Sidebar } Gideon Link to comment Share on other sites More sharing options...
zoeck Posted July 27, 2022 Share Posted July 27, 2022 9 hours ago, Roych said: thank you for anwser I's not working as it should. I'll try to be more clear what I need. Just replace if($page->hasChildren() || count($page->siblings(false))) with if($page->hasChildren()) Link to comment Share on other sites More sharing options...
Roych Posted July 27, 2022 Author Share Posted July 27, 2022 thank you for help, it was working half of the way, but then I decided to add a checkbox to define page as full screen so now I have full control over each article. Tank you very much R 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