0 posts
|
Here’s an example search page, something I think should be included in Frog by default.
Search code (save as “search” page):
<?php
function search($query, $parent) {
$results = array();
$top_level = $parent->children(array('order' => 'page.created_on DESC'));
foreach ($top_level as $r) {
if (strstr($r->title, "search")) { continue; }
if (preg_match("/$query/i", $r->title) || preg_match("/$query/i", $r->content())) {
array_push($results, $r);
foreach (search($query, $r) as $s) {
array_push($results, $s);
}
}
}
return $results;
}
$query = isset($_GET['q']) ? $_GET['q']:"";
if (strlen($query)<1) { echo "<p>Enter search terms in the box above.</p>"; }
else {
$results = search($query, $this->find('/'));
echo "<p>Results for <i>" . $query . "</i>:</p>";
if (count($results) < 1) { echo "<p>No results.</p>"; }
else {
echo "<ul>";
foreach ($results as $r) {
echo "<li>" . $r->link($r->title) . "</li>";
}
echo "</ul>";
}
}
?>
Search form (save as “search” snippet):
<form id="search-box" action="/search" method="get">
<p>
<input type="text" name="q" id="search" value="<?php echo $_GET['q'];?>" />
<button type="submit">Search</button>
</p>
</form>
Thoughts? |