Dean Posted June 25, 2014 Share Posted June 25, 2014 Hi, I currently have this code: $navigation = $page->rootParent->navigation if(count($navigation) > 0) { foreach($navigation as $p) { $children = $p->children; if(count($children) > 0) { // accordion header } else { // simple link } } } for outputting my navigation links, which works fine. But, for one section (news), I don't want the subpages (articles) to appear in the navigation. I have edited the code so that if(count($children) > 0) becomes if(count($children) > 0 && $p->title != 'News') so that news articles are excluded. But I think this is not a good way to do it. Can anyone share the normal/best way to exclude pages like this? Link to comment Share on other sites More sharing options...
arjen Posted June 25, 2014 Share Posted June 25, 2014 There are several options: Check if the $p has a specific template (or any other field). if(count($children) > 0 && $p->is("template!=news-item|other|template")) Or exclude above the loop like: $children = $p->children->not("template=news-item|other|template"); Or filter above the loop like: $children = $p->children->filter("template!=news-item|other|template"); See the excellent cheatsheet for more options in the PageArray/WireArray. Another option might be to use to use soma's navigation module. 4 Link to comment Share on other sites More sharing options...
Dean Posted June 25, 2014 Author Share Posted June 25, 2014 So easy, thanks! 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