Skip to content

Instantly share code, notes, and snippets.

@bastianallgeier
Forked from niklausgerber/Search.php
Created September 27, 2012 19:35
Show Gist options
  • Save bastianallgeier/3795979 to your computer and use it in GitHub Desktop.
Save bastianallgeier/3795979 to your computer and use it in GitHub Desktop.
Search Query
<?php snippet('header') ?>
<?php snippet('navigation') ?>
<section id="search">
<?php
$search = new search(array(
'searchfield' => 'q',
'ignore' => array('disclaimer', 'error', 'feed', 'home', 'imprint', 'sitemap', 'about'),
'mode' => 'and',
));
$results = $search->results();
?>
<form action="<?php echo thisURL() ?>">
<input type="text" placeholder="Search" name="q" id="search-field" /> <input type="submit" value="Search"/>
</form>
</section>
<?php if($results): ?>
<hr />
<!-- Display when search is ok -->
<section class="blog-archive">
<?php foreach($results as $result): ?>
<h3><a href="<?php echo $result->url() ?>"><?php echo $result->title() ?></a></h3>
<p><?php echo $result->published() ?></p>
<?php endforeach ?>
<section>
<!-- Display if search is not ok -->
<?php elseif($search->query()): ?>
<hr />
<section class="blog-archive">
<h3>No posts found matching «<?php echo html($search->query()) ?>».</h3>
<p>Your search for <span class="italic"><?php echo html($search->query()) ?></span> returned no results.</p>
</section>
<?php else: ?>
<!-- Only display following part if nothing was searched (I would like to have the search inside my blog overview page). If search is ok or not ok it will not be displayed. -->
<hr />
<section class="blog-archive">
<?php foreach($pages->find('blog')->children()->visible()->flip() as $article): ?>
<h3><a href="<?php echo $article->url() ?>"><?php echo html($article->title()) ?></a></h3>
<p><?php echo html($article->published()) ?></p>
<?php endforeach ?>
</section>
<?php endif ?>
<?php snippet('footer') ?>
<?php snippet('page-end') ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment