Advertisement
Beee

tpl-kb-search-results.php

Oct 26th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.25 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: KB Search results (new new)
  4.  *
  5.  * Description: Search results for SearchWP/Kennisbank
  6.  *
  7.  */
  8.  
  9. global $post;
  10.  
  11. // retrieve our search query if applicable
  12. $query = isset( $_REQUEST['swpquery'] ) ? sanitize_text_field( $_REQUEST['swpquery'] ) : '';
  13.  
  14. // retrieve our pagination if applicable
  15. $current_page = isset( $_REQUEST['swppg'] ) ? intval( $_REQUEST['swppg'] ) : 1;
  16. // $current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;
  17.  
  18. $soortString = isset($_REQUEST['soort']) ? sanitize_text_field($_REQUEST['soort']) : '';
  19.  
  20. $countryString = isset($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
  21.  
  22. $themaString = isset($_REQUEST['thema']) ? sanitize_text_field($_REQUEST['thema']) : '';
  23.  
  24. $kbSearch = new KBSearch;
  25.  
  26. get_header();
  27.  
  28.     if (!empty($query)) {
  29.         $result = $kbSearch->search($query, $soortString, $countryString, $themaString, $current_page);
  30.     }
  31.     else {
  32.         $result = $kbSearch->get_kb_items($soortString, $countryString, $themaString, $current_page);
  33.     }
  34.  
  35.     if ( get_current_user_id() == 1 ) {
  36.         echo '<pre>';
  37.         print_r($result);
  38.         // echo $result->count_posts;
  39.         // echo $result->posts;
  40.         echo '</pre>';
  41.     }
  42.  
  43.     $currentCategory = get_term_by('slug', $_GET['soort'], 'soort');
  44.     $term_children = get_term_children( $currentCategory->term_id, 'soort' );
  45.  
  46. get_template_part( 'partials/kb', 'search' );
  47. ?>
  48.  
  49. <div class="container container--narrow">
  50. <?php
  51.     // if there are subcats
  52.     if ( $term_children ) {
  53.         echo '<div class="subcats">';
  54.         echo '<h2 class="knowledge-list__title">'.__('Chapters', 'kncv').'</h2>';
  55.         echo '<ul>';
  56.         foreach ( $term_children as $subcategory ) {
  57.             $subcat = get_term_by( 'id', $subcategory, 'soort' );
  58.             echo '<li><a href="'.home_url().'/kennisbank/zoeken/?soort='.$subcat->slug.'">' . $subcat->name . '</a>';
  59.         }
  60.         echo '</ul>';
  61.         echo '</div>';
  62.     } else {
  63.         // if soort has no sub cats
  64.         get_template_part( 'partials/kb', 'filter' );
  65. ?>
  66.  
  67.     <section class="search-results">
  68.         <?php if ( !empty( $result->posts ) ) : ?>
  69.         <ul class="search-results__list">
  70.         <?php
  71.             foreach ( $result->posts as $post ) : setup_postdata( $post );
  72.                 get_template_part('partials/kb', 'search-result');
  73.             endforeach;
  74.         ?>
  75.         </ul>
  76.         <?php else: ?>
  77.             <p class="search-results__empty">No results found, please search again.</p>
  78.         <?php endif; ?>
  79.     </section>
  80.  
  81. <!-- begin pagination -->
  82. <?php
  83.  
  84.         if ( $result->max_num_pages > 1 ) {
  85.             // set up pagination
  86.             $pagination = paginate_links(array(
  87.                 'format' => '?swppg=%#%',
  88.                 'current' => $current_page,
  89.                 'total' => $result->max_num_pages,
  90.                 'show_all' => false,
  91.                 'end_size' => 3,
  92.                 'mid_size' => 2,
  93.                 'prev_next' => true,
  94.                 'prev_text' => __('&laquo;'),
  95.                 'next_text' => __('&raquo;')
  96.             ));
  97.  
  98.             echo sprintf('<div class="paging">%s</div>', $pagination);
  99.         }
  100.     }
  101.  
  102. ?>
  103.  
  104. </div>
  105.  
  106. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement