Advertisement
msaari

search.php

Jul 8th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.83 KB | None | 0 0
  1. <?php get_header(); ?>
  2.     <div id="content" class="row-fluid">
  3.  
  4.         <div id="main" class="span8" role="main">
  5.  
  6.             <?php global $query_string;
  7.            
  8.             if (isset($_GET['index']) && $_GET['s']==='Index') { // search by index
  9.                 $char = $_GET['index'];
  10.  
  11.                 if (strlen($char)===1 || strlen($char)===2 || preg_match('/^\p{L}+$/u', $char)) {
  12.                     $sql = "
  13.                        SELECT DISTINCT $wpdb->posts.*
  14.                        FROM $wpdb->posts, $wpdb->postmeta
  15.                        WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
  16.                        AND $wpdb->posts.post_title COLLATE UTF8_GENERAL_CI LIKE '$char%'
  17.                        AND $wpdb->posts.post_status = 'publish'
  18.                        AND $wpdb->posts.post_type = 'post'
  19.                        AND $wpdb->posts.post_date < NOW()
  20.                        ORDER BY $wpdb->posts.post_title DESC
  21.                    ";
  22.                     $search = $wpdb->get_results($sql, OBJECT);
  23.                 } else {
  24.                     echo 'Bad request!';
  25.                     die(0);
  26.                 }
  27.                
  28.             } else { // normal search
  29.             }
  30.  
  31.  
  32.             function this_loop() {
  33.                 ?>
  34.                 <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">
  35.                
  36.                     <!--header-->    
  37.                         <h3 class="search-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
  38.                        
  39.                         <!--p class="search-meta"><?php _e("Posted", "wpinit"); ?> <time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php the_date(); ?></time> <?php _e("by", "wpinit"); ?> <?php the_author_posts_link(); ?> <?php _e("in category", "wpinit"); ?> <?php the_category(', '); ?>.</p-->
  40.                    
  41.                     <!--/header--><!-- // article header -->    
  42.                     <!--footer>
  43.                         <p class="tags"><?php the_tags('<span class="tags-title">' . __("Tags","wpinit") . ':</span> ', ' ', ''); ?></p>
  44.                     </footer--><!-- / article footer -->
  45.                
  46.                 </article><!-- // article -->
  47.                 <?
  48.             }
  49.  
  50.             if (is_array($search) && count($search)!==0) {
  51.                 echo '
  52.                    <h1>Shëndeti nga A tek Zh</h1>
  53.                    <p>Zgjidhni nga indeksi alfabetik i artikujve të Doktori im për informacione rreth sëmundjeve dhe anomalive, testeve dhe studimeve, medikamente dhe trajtime.</p>
  54.                    ';
  55.                 foreach ($search as $post) {
  56.                     setup_postdata($post);
  57.                     this_loop();
  58.                 }
  59.             } else {
  60.                 echo '<h1>Rezultati kërkimeve</h1>';
  61.                                 if (function_exists('relevanssi_didyoumean')) { relevanssi_didyoumean(get_search_query(), "<p><br/>Mos ndoshta kishit parasysh: ", "</p> ", 5);
  62. }
  63.             echo '<ul id="search-results-types">';
  64.             global $rlv_search_result_cats;
  65.             if (is_array($rlv_search_result_cats)) {
  66.                 foreach($rlv_search_result_cats as $key => $val) {
  67.                     $name = get_the_category_by_ID($key);
  68.                     echo '<li>';
  69.                     echo '<a href="'.esc_url( home_url( '/' ) ).'?s='.get_search_query().'&cats='.$key.'">';
  70.                     echo $name . ' (' . $val . ')';
  71.                     echo '</a>';
  72.                     echo '</li>';
  73.                 }
  74.                 echo '</ul>';
  75.             }
  76.            
  77.                 if (have_posts()) {
  78.                     while (have_posts()) {
  79.                         the_post();
  80.                         this_loop();
  81.                     }
  82.             ?>
  83.            
  84.                 <nav class="wp-prev-next">
  85.                         <div class="prev"><?php previous_posts_link('&laquo; Kthehu') ?></div>
  86.                         <div class="next"><?php next_posts_link('Rezultate të tjera &raquo;') ?></div>
  87.                     </nav>
  88.            
  89.             <?php } else { ?>
  90.            
  91.             <article id="post-not-found">
  92.                 <header>
  93.                     <h1><?php _e("", "wpinit"); ?></h1>
  94.                 </header>
  95.                 <section class="post_content">
  96.                     <p><?php _e("Me vjen keq, por informacioni i kerkuar nuk gjendet ne faqe!", "wpinit"); ?></p>
  97.                     <p><?php _e("Kerkesa juaj do te plotësohet nga ne. ", "wpinit"); ?></p>
  98.                     <p><?php _e("Faleminderit", "wpinit"); ?></p>
  99.                 </section>
  100.                 <footer>
  101.                 </footer>
  102.             </article>
  103.            
  104.             <?php } } ?>
  105.    
  106.         </div><!-- // #main -->
  107.  
  108.         <div id="sidebar" class="span4">
  109.             <?php get_sidebar(); ?>
  110.         </div>
  111.        
  112.  
  113.     </div><!-- // #content -->
  114. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement