Tyssen Posted November 18, 2013 Share Posted November 18, 2013 I'm using the following search template: <?php /** * Search template * */ $outMain = ''; if($q = $sanitizer->selectorValue($input->get->q)) { $input->whitelist('q', $q); $matches = $pages->find("title|body|sidebar~=$q, limit=50"); $count = count($matches); if($count) { $outMain .= "<h1>Search results</h1> <p><strong>Found $count pages matching your query:</strong></p>" . "<ul class=\"nb\">"; foreach($matches as $m) { $outMain .= "<li> <h2 class=\"h4\"><a href='{$m->url}'>{$m->title}</a></h2> </li>"; } $outMain .= "</ul>"; } else { $outMain .= "<h2>Sorry, no results were found.</h2>"; } } else { $outMain .= "<p>Please enter a search term in the search box (upper right corner)</p>"; } include("./main.inc.php"); That works fine for pages that have their own URL but I have a bunch of child pages that don't have their own URLs, they're part of the parent page. How do I modify the code above so that the search result links to the parent page when the entry has no URL of its own? Link to comment Share on other sites More sharing options...
Wanze Posted November 18, 2013 Share Posted November 18, 2013 Hi Tyssen, Each page in ProcessWire has its own (unique) url. What do you mean with child-pages? Can you give an example how those pages are integrated in a parent page? Cheers Link to comment Share on other sites More sharing options...
Tyssen Posted November 19, 2013 Author Share Posted November 19, 2013 The pages are set up like: General Courses - Course 1 - Course 2 - Course 3 On the site, only a page for General Courses exists, all the individual courses are listed on that page, they don't have their own unique page that you can visit. Link to comment Share on other sites More sharing options...
Harmster Posted November 19, 2013 Share Posted November 19, 2013 Page or Template? Because you say subpage, but if it isnt a child page the word subpage is confusing, How did you set up the Courses? as fields? as text? or as a child page? Link to comment Share on other sites More sharing options...
Wanze Posted November 19, 2013 Share Posted November 19, 2013 If your course template has the fields "title|body|sidebar", they should be searched too. If these "sub-pages" are hidden, you need to add "include=hidden" to your selector string. For the results: foreach($matches as $m) { $outMain .= "<li>" $url = ($m->template == 'course') ? $m->parent->url : $m->url; $title = ($m->template == 'course') ? $m->parent->title : $m->title; <h2 class=\"h4\"><a href='{$url}'>{$title}</a></h2> </li>"; } Note that the parent page may be listed multiple times with this code. 2 Link to comment Share on other sites More sharing options...
Tyssen Posted November 19, 2013 Author Share Posted November 19, 2013 Thanks Wanze, that's what I'm after. 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