Skip to content

Instantly share code, notes, and snippets.

@bastianallgeier
Created January 2, 2012 16:22
Show Gist options
  • Save bastianallgeier/1551286 to your computer and use it in GitHub Desktop.
Save bastianallgeier/1551286 to your computer and use it in GitHub Desktop.
Search Template for Kirby
<!-- site/snippets/pagination.php -->
<nav role="pagination">
<div class="count">
<strong><?php echo $pagination->countItems() ?></strong> Results / showing <strong><?php echo $pagination->numStart() ?></strong> - <strong><?php echo $pagination->numEnd() ?></strong>
</div>
<div class="buttons">
<? if($pagination->hasPrevPage()): ?>
<a class="prev" href="<?= $pagination->prevPageURL() ?>">&lsaquo; previous</a>
<? else: ?>
<span class="prev">&lsaquo; previous</span>
<? endif ?>
<? if($pagination->hasNextPage()): ?>
<a class="next" href="<?= $pagination->nextPageURL() ?>">next &rsaquo;</a>
<? else: ?>
<span class="next">next &rsaquo;</span>
<? endif ?>
</div>
</nav>
<!-- site/templates/search.php -->
<?php snippet('header') ?>
<?php snippet('menu') ?>
<?php
$search = new search(array(
'searchfield' => 'q',
'ignore' => array('search', 'error'),
'words' => true,
'paginate' => 10
));
$results = $search->results();
?>
<h1><?php echo html($page->title()) ?></h1>
<form action="<?php echo thisURL() ?>">
<input type="text" placeholder="Type in your searchword…" name="q" value="<?php echo html($search->query()) ?>" />
<input type="submit" value="Search" />
</form>
<?php if($results): ?>
<?php snippet('pagination', array('pagination' => $results->pagination())) ?>
<ul>
<?php foreach($results as $row): ?>
<li>
<strong><a href="<?php echo $row->url() ?>"><?php echo html($row->title()) ?></a></strong>
<a href="<?php echo $row->url() ?>"><?php echo html($row->url()) ?></a>
</li>
<?php endforeach ?>
</ul>
<?php snippet('pagination', array('pagination' => $results->pagination())) ?>
<?php elseif($search->query()): ?>
<div class="no-results">No results for <strong><?php echo html($search->query()) ?></strong></div>
<?php endif ?>
<?php snippet('footer') ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment