Advertisement
Guest User

LG search

a guest
Sep 2nd, 2011
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.19 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Search Page
  4. */
  5.  
  6. get_header(); ?>
  7.  
  8.     <div id="content" class="narrowcolumn" role="main">
  9.     <?php
  10.     get_search_form();
  11.  
  12.     global $query_string;
  13.  
  14.     $query_args = explode("&", $query_string);
  15.     $search_query = array();
  16.  
  17.     foreach($query_args as $key => $string) {
  18.         $query_split = explode("=", $string);
  19.         $search_query[$query_split[0]] = urldecode($query_split[1]);
  20.     } // foreach
  21.  
  22.     $search = new WP_Query($search_query);
  23.    
  24.     $job = wp_specialchars(stripslashes($_GET["job"]), 1);
  25.     $opportunity = wp_specialchars(stripslashes($_GET["opportunity"]), 1);
  26.     $resource = wp_specialchars(stripslashes($_GET["resource"]), 1);
  27.  
  28.     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  29.     $cat = (get_query_var('cat')) ? get_query_var('cat') : 0;
  30.     $searchtag = (get_query_var('tag')) ? get_query_var('tag') : '';
  31.     if(isset($_GET['post_type'])) {
  32.         $ptype = $_GET['post_type'];
  33.     }
  34.     else {
  35.         $ptype = '';
  36.     }
  37.     if($ptype) :
  38.     unset($_GET['post_type']);
  39.     switch($ptype) {
  40.         case 'post':
  41.         case 'page':
  42.         case 'any':
  43.             $stype = trim($ptype);
  44.             if(0 != $cat) $stype = 'post';
  45.         break;
  46.         default:
  47.             $stype = 'any';
  48.         break;
  49.     }
  50.     else :
  51.         $stype = 'any';
  52.     endif;
  53.    
  54.     $args = array(
  55.         's' => $s,
  56.         'paged' => $paged,
  57.         'orderby' => '',
  58.         'order' => '',
  59.         'cat' => $cat,
  60.         'post_type' => $stype,
  61.         'category__in' => '',
  62.         'category__and' => '',
  63.         'post__in' => '',
  64.         'post__not_in' => '',
  65.         'tag' => $searchtag,
  66.         'tag__in' => '',
  67.         'tag__not_in' => ''
  68.     );
  69.  
  70.     query_posts( $args );
  71.    
  72.     // If there's results for the search
  73.     if (have_posts()) :
  74.    
  75.     // Total results found
  76.     $total_found = $wp_query->found_posts;
  77.     // Last possible item on page
  78.     $last_on_page = $paged * $posts_per_page;
  79.     // First item on page
  80.     $first_on_page = ($last_on_page - $posts_per_page) + 1;
  81.     // If last possible item is more then total found, then the total is the last item for this page (the last page)
  82.     if($total_found < $last_on_page) {
  83.         // Last page
  84.         $results_now = $first_on_page .' - '. $total_found;
  85.         // EXAMPLE: 5-8 of 8
  86.     }
  87.     else {
  88.         // Any other page
  89.         $results_now = $first_on_page .' - '. $last_on_page;
  90.         // EXAMPLE: 1-5 of 8
  91.     }
  92.     ?>
  93.         <h2 class="pagetitle">Search Results</h2>
  94.             <?php posts_nav_link(' ','< Previous','Next >'); ?>
  95.         <?php while (have_posts()) : the_post(); ?>
  96.             <div class="post_entry">
  97.             <div class="post-thumb"><?php the_post_thumbnail('single-post-thumbnail'); ?></div>
  98.             <h4 class="post-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
  99.             <p class="post_categories">Posted In: <?php $terms = wp_get_post_terms($post->ID); $names = array(); foreach($terms as $term){$names[] = $term->name;} echo implode(', ', $names); ?><?php $terms = wp_get_post_terms($post->ID,'opportunitytype'); foreach($terms as $term){echo ', ' . $term->name;} ?>.</p></h4>
  100.  
  101.             <?php  
  102.                 $location = get_post_meta($post->ID, 'location', TRUE);
  103.                 $organization = get_post_meta($post->ID, 'organization', TRUE);
  104.                 $url = get_post_meta($post->ID, 'url', TRUE);
  105.             ?>
  106.             <div class="post-meta">
  107.                 <?php if($organization != ''){ ?><p class="post_meta_organization"><?php echo $organization; ?></p><?php } ?>
  108.                 <?php if($location != ''){ ?><p class="post_meta_location"><?php echo $location; ?></p><?php } ?>
  109.                 <?php if($url != ''){ ?><p class="post_meta_url">Website: <a href="<?php echo $url; ?>">Click Here</a></p><?php } ?>
  110.             </div>
  111.             <div class="hidden tags<?php $terms = wp_get_post_terms($post->ID,'jobtype'); foreach($terms as $term){echo ' ' . $term->slug;} ?><?php $terms = wp_get_post_terms($post->ID,'opportunitytype'); foreach($terms as $term){echo ' ' . $term->slug;} ?>"></div>
  112.            
  113.             <p class="post_excerpt"><?php the_excerpt(); ?></p>
  114.                 <?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
  115.  
  116.         <?php comments_template( '', true ); ?>
  117. </div>
  118.         <?php endwhile; ?>
  119.        
  120.         <div style="text-align:center">
  121.             <?php posts_nav_link(' ','< Previous','Next >'); ?>
  122.         </div>
  123.  
  124.     <?php else : ?>
  125.  
  126.         <h2 class="center">No posts or pages matched the search.</h2>
  127.         <br />
  128.        
  129.     <?php endif; ?>
  130.  
  131.     </div>
  132.  
  133. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement