Jump to content

List only parents in search results when page is hidden


joe_ma
 Share

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...