SearchWP theme template integrating a supplemental search engine with the Term Archive Priority Extension activated
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 | |
/* Template Name: SearchWP Custom Search */ | |
global $post; | |
$query = isset( $_GET['searchwpquery'] ) ? sanitize_text_field( $_GET['searchwpquery'] ) : ''; | |
$page = isset( $_GET['swppage'] ) ? absint( $_GET['swppage'] ) : 1; | |
the_post(); | |
get_header(); ?> | |
<div id="primary" class="content-area"> | |
<div id="content" class="site-content" role="main"> | |
<?php if( !empty( $query ) ) : ?> | |
<header class="page-header"> | |
<h1 class="page-title">Search Results for: <?php echo $query; ?></h1> | |
</header> | |
<?php endif; ?> | |
<div class="entry-content"> | |
<form action="" method="get"> | |
<fieldset> | |
<legend>Supplemental Search</legend> | |
<p> | |
<label for="searchwpquery">Search</label> | |
<input type="text" id="searchwpquery" name="searchwpquery" value="<?php echo esc_attr( $query ); ?>" /> | |
</p> | |
<p><button type="submit">Search</button></p> | |
</fieldset> | |
</form> | |
</div> | |
<?php if( !empty( $query ) ) : ?> | |
<?php | |
$engine = SearchWP::instance(); // instatiate SearchWP | |
$supplementalEngineName = 'supplemental'; // search engine name | |
// perform the search | |
$posts = $engine->search( $supplementalEngineName, $query, $page ); | |
?> | |
<?php if( !empty( $posts ) ) : ?> | |
<?php foreach( $posts as $post ) : ?> | |
<?php if( $post instanceof SearchWPTermResult ) : ?> | |
<article> | |
<header class="entry-header"> | |
<h1 class="entry-title"> | |
<a href="<?php echo $post->link; ?>" rel="bookmark"><?php echo $post->taxonomy; ?>: <?php echo $post->name; ?></a> | |
</h1> | |
</header><!-- .entry-header --> | |
<div class="entry-summary"> | |
<p><?php echo $post->description; ?></p> | |
</div><!-- .entry-summary --> | |
</article> | |
<?php else : setup_postdata( $post ); ?> | |
<article> | |
<header class="entry-header"> | |
<h1 class="entry-title"> | |
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> | |
</h1> | |
</header><!-- .entry-header --> | |
<div class="entry-summary"> | |
<?php the_excerpt(); ?> | |
</div><!-- .entry-summary --> | |
</article> | |
<?php endif; ?> | |
<?php endforeach; ?> | |
<?php endif; ?> | |
<?php endif; ?> | |
</div><!-- #content --> | |
</div><!-- #primary --> | |
<?php | |
wp_reset_postdata(); | |
get_sidebar(); | |
get_footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment