Plak onderstaande code in de search.php van het thema. Deze gebruikt de standaard zoekmachine om de resultaten te tonen van de SearchWP zoekmachine.

<?php 
global $post;

// retrieve our search query if applicable
$query = isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';

// retrieve our pagination if applicable
$swppg = isset( $_REQUEST['swppg'] ) ? absint( $_REQUEST['swppg'] ) : 1;

if ( class_exists( 'SWP_Query' ) ) {

	$engine = 'default';

	$swp_query = new SWP_Query(
		// see all args at https://searchwp.com/docs/swp_query/
		array(
			's'      => $query,
			'posts_per_page' => 10,
			'nopaging' => false,
			'page'   => $swppg,
		)
	);
	// set up pagination
$pagination = paginate_links( array(
		'format'  => '?swppg=%#%',
		'current' => $swppg,
		'total'   => $swp_query->max_num_pages,
	) );
}

get_header(); ?>

<div class="container-fluid cntnt">

	<!-- section -->
	<div class="container">
		<div class="row">
			<div class="col-xs-12 col-sm-12 col-md-12">
				<div class="content-container clear" id="rslts">
					<?php if ( ! empty( $query ) && isset( $swp_query ) && ! empty( $swp_query->posts ) ) {
						echo $swp_query->found_posts.' gevonden<br/>';				
						echo $swp_query->max_num_pages;
					foreach ( $swp_query->posts as $post ) {
					setup_postdata( $post );?>
						<?php $post_type = get_post_type(); ?>
						<article class="row srchpst" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
							<?php if ( has_post_thumbnail() ):?>
							<div class="hidden-xs col-sm-3 col-md-2">
								<?php the_post_thumbnail(); ?>
							</div>
							<?php endif; ?>
							<?php if ( has_post_thumbnail() ):?>
							<div class="col-xs-12 col-sm-9 col-md-10">
							<?php else: ?>
							<div class="col-xs-12 col-sm-12 col-md-12">
							<?php endif; ?>
								<h3 style="margin-top: 0px;"><?php the_title();?></h3>
								<p><?php echo wp_trim_words( get_the_content(), 100, '...' ); ?></p>
								<a href="<?php the_permalink(); ?>" class="btn">Bekijk</a>
							</div>
							<div class="col-xs-12 brdr"></div>
						</article>

					<?php
				}
				
				wp_reset_postdata();
				// pagination
				if ( $swp_query->max_num_pages > 1 ) { ?>
					<div class="navigation pagination" role="navigation">
						<div class="nav-links">
							<?php echo wp_kses_post( $pagination ); ?>
						</div>
					</div>
					<br/>
				<?php }
			} else {
				?><p>Geen resultaten gevonden. Wellicht moet u uw zoekterm aanpassen.</p>
					<form action="/" method="get" class="srchtp bdy"><input type="text" name="s" placeholder="Hier zoeken..." id="search" value="<?php the_search_query(); ?>" /><button type="submit" class="nsd"><i class="fa fa-search"></i></button></form>
				<?php
			} ?>

					
				</div>

			</div>

		</div>


	</div>


</div>
<?php get_footer(); ?>

Deze zijn net met AJAX pagination netjes te maken. https://wiki.webmazing.nl/?p=559

Geef een reactie 0