Created
April 18, 2014 17:06
-
-
Save jchristopher/11054399 to your computer and use it in GitHub Desktop.
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: Advance Search Template */ | |
global $post; | |
// retrieve our search query if applicable | |
$query = isset( $_REQUEST['swpquery'] ) ? sanitize_text_field( $_REQUEST['swpquery'] ) : ''; | |
// retrieve our pagination if applicable | |
$swppg = isset( $_REQUEST['swppg'] ) ? absint( $_REQUEST['swppg'] ) : 1; ?> | |
<?php get_header(); ?> | |
<div id="content"> | |
<?php if(of_get_option('fw_blog', 'no') == 'no'): ?><div id="content-sidebar"><?php endif; ?> | |
<!-- begin search form --> | |
<form action="" method="get"> | |
<p> | |
<label for="swpquery"><?php _e( 'Search', 'twentythirteen' ); ?></label> | |
<input type="text" name="swpquery" id="swpquery" value="<?php echo esc_attr( $query ); ?>" /> | |
</p> | |
<p> | |
<input type="hidden" name="" id="" value="" /> | |
<input name="submit" type="submit" id="swpsubmit" value="<?php _e( 'Search', 'twentythirteen' ); ?>" /> | |
</p> | |
</form> | |
<!-- end search form --> | |
<?php if( !empty( $query ) && class_exists( 'SearchWP' ) ) : ?> | |
<?php | |
// instantiate SearchWP | |
$engine = SearchWP::instance(); | |
$supplementalSearchEngineName = 'auth_sup_search'; | |
// set up custom posts per page | |
function mySearchEnginePostsPerPage() { | |
return 10; // 10 posts per page | |
} | |
add_filter( 'searchwp_posts_per_page', 'mySearchEnginePostsPerPage' ); | |
// perform the search | |
$posts = $engine->search( $supplementalSearchEngineName, $query, $swppg ); | |
// set up pagination | |
$prevPage = $swppg > 1 ? $swppg - 1 : false; | |
$nextPage = $swppg < $engine->maxNumPages ? $swppg + 1 : false; | |
?> | |
<?php if( !empty( $posts ) ) : ?> | |
<header class="page-header"> | |
<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentythirteen' ), $query ); ?></h1> | |
</header> | |
<?php /* The loop */ ?> | |
<?php foreach ( $posts as $post ): setup_postdata( $post ); ?> | |
<?php | |
// you can use any and all WordPress functions here, to keep things aligned | |
// with the Twenty Thirteen example we're just going to do what it does in | |
// it's search.php template, but you can customize this with anything | |
get_template_part( 'content', get_post_format() ); | |
?> | |
<?php endforeach; ?> | |
<?php wp_reset_postdata(); ?> | |
<!-- begin pagination --> | |
<?php if( $engine->maxNumPages > 1 ) : ?> | |
<nav class="navigation paging-navigation" role="navigation"> | |
<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1> | |
<div class="nav-links"> | |
<?php if( $prevPage ) : ?> | |
<div class="nav-previous"> | |
<a href="?swpquery=<?php echo urlencode( $query ); ?>&swppg=<?php echo $prevPage; ?>"> | |
<?php _e( '<span class="meta-nav">←</span> Older posts', 'twentythirteen' ); ?> | |
</a> | |
</div> | |
<?php endif; ?> | |
<?php if( $nextPage ) : ?> | |
<div class="nav-previous"> | |
<a href="?swpquery=<?php echo urlencode( $query ); ?>&swppg=<?php echo $nextPage; ?>"> | |
<?php _e( 'Newer posts <span class="meta-nav">→</span>', 'twentythirteen' ); ?> | |
</a> | |
</div> | |
<?php endif; ?> | |
</div><!-- .nav-links --> | |
</nav><!-- .navigation --> | |
<?php endif; ?> | |
<!-- end pagination --> | |
<?php else : ?> | |
<?php get_template_part( 'content', 'none' ); ?> | |
<?php endif; ?> | |
<?php endif; ?> | |
<?php if(of_get_option('fw_blog', 'no') == 'no'): ?></div><!-- close #content-sidebar --><?php endif; ?> | |
<?php if(of_get_option('fw_blog', 'no') == 'no'): ?><?php get_sidebar(); ?><?php endif; ?> | |
<div class="clearfix"></div> | |
</div><!-- close #content --> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment