Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: KB Search results (new new)
- *
- * Description: Search results for SearchWP/Kennisbank
- *
- */
- global $post;
- // retrieve our search query if applicable
- $query = isset( $_REQUEST['swpquery'] ) ? sanitize_text_field( $_REQUEST['swpquery'] ) : '';
- // retrieve our pagination if applicable
- $current_page = isset( $_REQUEST['swppg'] ) ? intval( $_REQUEST['swppg'] ) : 1;
- // $current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;
- $soortString = isset($_REQUEST['soort']) ? sanitize_text_field($_REQUEST['soort']) : '';
- $countryString = isset($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
- $themaString = isset($_REQUEST['thema']) ? sanitize_text_field($_REQUEST['thema']) : '';
- $kbSearch = new KBSearch;
- get_header();
- if (!empty($query)) {
- $result = $kbSearch->search($query, $soortString, $countryString, $themaString, $current_page);
- }
- else {
- $result = $kbSearch->get_kb_items($soortString, $countryString, $themaString, $current_page);
- }
- if ( get_current_user_id() == 1 ) {
- echo '<pre>';
- print_r($result);
- // echo $result->count_posts;
- // echo $result->posts;
- echo '</pre>';
- }
- $currentCategory = get_term_by('slug', $_GET['soort'], 'soort');
- $term_children = get_term_children( $currentCategory->term_id, 'soort' );
- get_template_part( 'partials/kb', 'search' );
- ?>
- <div class="container container--narrow">
- <?php
- // if there are subcats
- if ( $term_children ) {
- echo '<div class="subcats">';
- echo '<h2 class="knowledge-list__title">'.__('Chapters', 'kncv').'</h2>';
- echo '<ul>';
- foreach ( $term_children as $subcategory ) {
- $subcat = get_term_by( 'id', $subcategory, 'soort' );
- echo '<li><a href="'.home_url().'/kennisbank/zoeken/?soort='.$subcat->slug.'">' . $subcat->name . '</a>';
- }
- echo '</ul>';
- echo '</div>';
- } else {
- // if soort has no sub cats
- get_template_part( 'partials/kb', 'filter' );
- ?>
- <section class="search-results">
- <?php if ( !empty( $result->posts ) ) : ?>
- <ul class="search-results__list">
- <?php
- foreach ( $result->posts as $post ) : setup_postdata( $post );
- get_template_part('partials/kb', 'search-result');
- endforeach;
- ?>
- </ul>
- <?php else: ?>
- <p class="search-results__empty">No results found, please search again.</p>
- <?php endif; ?>
- </section>
- <!-- begin pagination -->
- <?php
- if ( $result->max_num_pages > 1 ) {
- // set up pagination
- $pagination = paginate_links(array(
- 'format' => '?swppg=%#%',
- 'current' => $current_page,
- 'total' => $result->max_num_pages,
- 'show_all' => false,
- 'end_size' => 3,
- 'mid_size' => 2,
- 'prev_next' => true,
- 'prev_text' => __('«'),
- 'next_text' => __('»')
- ));
- echo sprintf('<div class="paging">%s</div>', $pagination);
- }
- }
- ?>
- </div>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement