Search templates

Here’s my search template for anyone that’s looking for one. Copy this into search.php under templates.

<!-- site/templates/search.php -->
<?php snippet('header') ?>
<div class="text">

	<?php if($results): ?>
		<?php foreach($results as $result): ?>
			<div class="text">
					<h1><a href="<?php echo $result->url() ?>">

							<?php
							$breadcrumb = '';
							foreach($result->parents()->flip() as $parent) {
								echo  $parent->title()->html(). ' » ';

							}?>

							<?php echo $result->title() ?></a></h1>
						<p>
							<?php echo $result->description() ?> <?php echo excerpt($result->text(), 300) ?> [...] <a href="<?php echo $result->url() ?>">Read more.</a>
						</p>
			</div>
		<?php endforeach ?>
			<div>
				<?php snippet('pagination', array('pagination' => $results->pagination())) ?>
			</div>
	<?php elseif($search->query()): ?>
			<div>
				<h3>No posts found matching «<?php echo html($search->query()) ?>».</h3>
				<p>Your search for <strong><?php echo html($search->query()) ?></strong> returned no results.</p>
			</div>
	<?php endif ?>
			<h3>Tags</h3>
			<p>
				<?php foreach($tags as $tag): ?>
					<a href="<?php echo $tag->url() ?>">#<?php echo $tag->name() ?></a>
				<?php endforeach ?>
			</p>
</div>

<?php snippet('footer') ?>


2 Likes