joe_ma Posted March 13, 2018 Share Posted March 13, 2018 Hi I've got the following tree of pages: - page with press overviews per month - page 1 with press overview per day (hidden, template=pressespiegel) - page 2 with press overview per day (hidden, template=pressespiegel) - page 3 with press overview per day (hidden, template=pressespiegel) - … The template of the parent page lists the child pages. I'd like to modify search.php so as to search the child pages for the search term, but if the page has the template of "pressespiegel" list only the parent page. So my code looks like this: //look also in hidden pages $selector = "title|body~=$q, include=hidden, limit=50"; // Find pages that match the selector $matches = $pages->find($selector); //new array to store the final list of results //because I don't want to list hidden pages $result = new PageArray(); foreach ($matches as $m){ //if the page is hidden, list the parent of the page //because subpages are already listed via template of the parent page if ($m("template=pressespiegel")){ $result->add($m->parent); } else { //otherwise add the page $result->add($m); } //list parent pages only once $result->unique(); } // then put out $result But this results in always listing the parent pages, even when they don't have the template "pressespiegel". Thanks for help. Link to comment Share on other sites More sharing options...
ottogal Posted March 13, 2018 Share Posted March 13, 2018 Quote if ($m("template=pressespiegel")){ Shouldn't that be if ($m->template->name == "pressespiegel"){ ? 1 Link to comment Share on other sites More sharing options...
joe_ma Posted March 13, 2018 Author Share Posted March 13, 2018 Yes, it should. Thanks a lot! 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