Last active
September 27, 2017 08:55
-
-
Save niguli/fea94eeed7814a99ad4d02d57a4274dc to your computer and use it in GitHub Desktop.
page-searchwp-supplemental template
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 Supplemental Search Results */ | |
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; | |
if ( class_exists( 'SWP_Query' ) ) { | |
$engine = 'default'; // taken from the SearchWP settings screen | |
$swp_query = new SWP_Query( | |
// see all args at https://searchwp.com/docs/swp_query/ | |
array( | |
's' => $query, | |
'engine' => $engine, | |
'page' => $swppg, | |
) | |
); | |
// set up pagination | |
$pagination = paginate_links( array( | |
'format' => '?swppg=%#%', | |
'current' => $swppg, | |
'total' => $swp_query->max_num_pages, | |
) ); | |
} | |
get_header(); ?> | |
<section id="primary" class="content-area"> | |
<main id="main" class="site-main" role="main"> | |
<header class="page-header"> | |
<h1 class="page-title"> | |
<?php if ( ! empty( $query ) ) : ?> | |
<?php printf( __( 'Ecco i risultati per la ricerca: %s', 'MaterDei' ), $query ); ?> | |
<?php else : ?> | |
SearchWP Supplemental Search | |
<?php endif; ?> | |
</h1> | |
<!-- begin search form --> | |
<div class="search-box"> | |
<form role="search" method="get" class="search-form" action="<?php echo get_permalink( 2226 ); ?>"> | |
<label> | |
<span class="screen-reader-text">Cerca:</span> | |
<input type="search" class="search-field" placeholder="Cerca di nuovo …" value="" name="swpquery" title="Cerca:"> | |
</label> | |
<input type="submit" class="search-submit" value="Cerca"> | |
</form> | |
</div> | |
<!-- end search form --> | |
</header><!-- .page-header --> | |
<?php if ( ! empty( $query ) && isset( $swp_query ) && ! empty( $swp_query->posts ) ) { | |
foreach ( $swp_query->posts as $post ) { | |
setup_postdata( $post ); | |
// output the result | |
?> | |
<div class="search-result"> | |
<h2> | |
<a href="<?php echo get_permalink(); ?>"> | |
<?php the_title(); ?> | |
</a> | |
<?php the_excerpt(); ?> | |
</h2> | |
</div> | |
<?php | |
} | |
wp_reset_postdata(); | |
// pagination | |
if ( $swp_query->max_num_pages > 1 ) { ?> | |
<div class="navigation pagination" role="navigation"> | |
<h2 class="screen-reader-text">Posts navigation</h2> | |
<div class="nav-links"> | |
<?php echo wp_kses_post( $pagination ); ?> | |
</div> | |
</div> | |
<?php } | |
} else { | |
?><p>Spiacente, nessun risultato trovato.</p><?php | |
} ?> | |
</main><!-- .site-main --> | |
</section><!-- .content-area --> | |
<?php get_footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment