Advertisement
Beee

kb-search.php

Oct 26th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.40 KB | None | 0 0
  1. <?php
  2.  
  3. // template for search form
  4.  
  5. if (isset($_GET['soort'])) :
  6.     // get current category
  7.     $currentCategory = get_term_by('slug', $_GET['soort'], 'soort');
  8.  
  9.     if ($currentCategory) :
  10.     ?>
  11.     <div class="container container--narrow">
  12.         <?php
  13.             $soort_image = get_field('soort_image', 'soort_'.$currentCategory->term_id);
  14.             // print_r($soort_image);
  15.             if ( $soort_image !== false ) {
  16.                 $cat_img_array = wp_get_attachment_image_src( $soort_image, 'kennisbank', false );
  17.                 $cat_img = $cat_img_array[0];
  18.             }
  19.         ?>
  20.         <section class="filter-info <?php if ( $cat_img) { echo 'met-image'; } ?>">
  21.             <?php if ( $cat_img) { ?>
  22.             <img class="filter-info__image" src="<?php echo $cat_img; ?>" alt="" />
  23.             <?php } ?>
  24.             <div class="filter-info__info">
  25.                 <h1 class="filter-info__title"><?php echo $currentCategory->name; ?></h1>
  26.                 <p class="filter-info__description"><?php echo term_description($currentCategory->term_id, 'soort'); ?></p>
  27.             </div>
  28.         </section>
  29.     </div>
  30.     <?php
  31.     endif;
  32. endif;
  33.  
  34. // get children of current category
  35. $term_children = get_term_children( $currentCategory->term_id, 'soort' );
  36. // if there are no children
  37. if ( !$term_children ) {
  38.  
  39.     if ( isset( $_REQUEST['swpquery'] )) {
  40.         $query = esc_html($_REQUEST['swpquery']);
  41.     }
  42.     else {
  43.         $query = '';
  44.     }
  45.  
  46.     if ( isset( $_REQUEST['soort'] )) {
  47.         $soort = esc_html($_REQUEST['soort']);
  48.     }
  49.     else {
  50.         $soort = '';
  51.     }
  52.  
  53.     $split_soort = explode(",", $soort);
  54.  
  55.     if ( isset( $_REQUEST['thema'] )) {
  56.         $thema = esc_html($_REQUEST['thema']);
  57.     }
  58.     else {
  59.         $thema = '';
  60.     }
  61.  
  62.     $split_thema = explode(",", $thema);
  63.  
  64.     if ( isset( $_REQUEST['country'] )) {
  65.         $country = esc_html($_REQUEST['country']);
  66.     }
  67.     else {
  68.         $country = '';
  69.     }
  70.  
  71.     $split_country = explode(",", $country);
  72.  
  73.     $placeholder_zoeken = __("Search for title, document type or another search term", "kncv");
  74.     $search             = __("Search", "kncv");
  75.     $advanced_search    = __("Advanced search", "kncv");
  76. ?>
  77. <form role="search" method="get" class="search" action="<?php echo get_permalink(icl_object_id(32, 'page', true)); ?>">
  78.     <div class="container container--narrow">
  79.         <fieldset class="search__terms">
  80.             <label class="search__label" for="search-knowledgebase"><?php echo $search; ?></label>
  81.             <input class="search__input" type="search" id="search-knowledgebase" name="swpquery" value="<?php echo $query; ?>" placeholder="<?php echo $placeholder_zoeken; ?>">
  82.             <button class="search__submit" type="submit"><?php echo $search; ?></button>
  83.         </fieldset>
  84.  
  85. <?php
  86.     // advanced search
  87.  
  88.     $countries = get_posts( array( 'post_type' => 'land', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => '-1', 'suppress_filters' => 0 ));
  89.     $soorten   = get_terms( 'soort', array( 'hide_empty' => true, 'suppress_filters' => 1 ) );
  90.     $themas    = get_terms( 'thema', array( 'hide_empty' => true, 'suppress_filters' => 0 ) );
  91. ?>
  92.         <fieldset class="search__advanced">
  93.             <legend class="search__toggle-advanced"><?php echo $advanced_search; ?></legend>
  94. <?php if ( !empty($countries) ) { ?>
  95.  
  96.             <input type="hidden" name="country">
  97.             <ul class="search__filters">
  98.             <?php foreach ( $countries as $country ) { ?>
  99.             <li class="search__filter">
  100.                 <label class="checkbox-label search__filter-label">
  101.                     <input type="checkbox" class="checkbox search__filter-checkbox" data-search-filter="country" name="<?php echo $country->post_name; ?>" value="<?php echo $country->post_name; ?>" <?php if ( in_array( $country->post_name, $split_country) ) { echo " checked"; } ?>> <?php echo $country->post_title; ?>
  102.                 </label>
  103.             </li>
  104.             <?php } ?>
  105.         </ul>
  106. <?php } if ( !empty($soorten) ) { ?>
  107.  
  108.         <input type="hidden" name="soort" value="<?php echo $soort; ?>">
  109.         <ul class="search__filters">
  110. <?php foreach ( $soorten as $soort ) { ?>
  111.             <li class="search__filter">
  112.                 <label class="checkbox-label search__filter-label">
  113.                     <input type="checkbox" class="checkbox search__filter-checkbox" data-search-filter="soort" name="taxonomy" value="<?php echo $soort->slug; ?>" <?php if ( in_array( $soort->slug, $split_soort) ) { echo " checked"; } ?>> <?php echo kncv_translated_term_name($soort); ?>
  114.                 </label>
  115.             </li>
  116. <?php } ?>
  117.         </ul>
  118. <?php } ?>
  119.  
  120. <?php if ( !empty($themas) ) { ?>
  121.  
  122.         <input type="hidden" name="thema" value="<?php echo $thema; ?>">
  123.         <ul class="search__filters">
  124. <?php foreach ( $themas as $thema ) { ?>
  125.             <li class="search__filter">
  126.                 <label class="checkbox-label search__filter-label">
  127.                     <input type="checkbox" class="checkbox search__filter-checkbox" data-search-filter="thema" name="taxonomy" value="<?php echo $thema->slug; ?>" <?php if ( in_array( $thema->slug, $split_thema) ) { echo " checked"; } ?>> <?php echo kncv_translated_term_name($thema); ?>
  128.                 </label>
  129.             </li>
  130. <?php
  131.         }
  132.         echo '</ul>';
  133.     }
  134. ?>
  135.         </fieldset>
  136.     </div>
  137. </form>
  138. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement