Created
September 27, 2012 16:50
-
-
Save niklausgerber/3795071 to your computer and use it in GitHub Desktop.
Search Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 endif ?> | |
<!-- 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 snippet('footer') ?> | |
<?php snippet('page-end') ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment