Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: Search Page
- */
- get_header(); ?>
- <div id="content" class="narrowcolumn" role="main">
- <?php
- get_search_form();
- global $query_string;
- $query_args = explode("&", $query_string);
- $search_query = array();
- foreach($query_args as $key => $string) {
- $query_split = explode("=", $string);
- $search_query[$query_split[0]] = urldecode($query_split[1]);
- } // foreach
- $search = new WP_Query($search_query);
- $job = wp_specialchars(stripslashes($_GET["job"]), 1);
- $opportunity = wp_specialchars(stripslashes($_GET["opportunity"]), 1);
- $resource = wp_specialchars(stripslashes($_GET["resource"]), 1);
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
- $cat = (get_query_var('cat')) ? get_query_var('cat') : 0;
- $searchtag = (get_query_var('tag')) ? get_query_var('tag') : '';
- if(isset($_GET['post_type'])) {
- $ptype = $_GET['post_type'];
- }
- else {
- $ptype = '';
- }
- if($ptype) :
- unset($_GET['post_type']);
- switch($ptype) {
- case 'post':
- case 'page':
- case 'any':
- $stype = trim($ptype);
- if(0 != $cat) $stype = 'post';
- break;
- default:
- $stype = 'any';
- break;
- }
- else :
- $stype = 'any';
- endif;
- $args = array(
- 's' => $s,
- 'paged' => $paged,
- 'orderby' => '',
- 'order' => '',
- 'cat' => $cat,
- 'post_type' => $stype,
- 'category__in' => '',
- 'category__and' => '',
- 'post__in' => '',
- 'post__not_in' => '',
- 'tag' => $searchtag,
- 'tag__in' => '',
- 'tag__not_in' => ''
- );
- query_posts( $args );
- // If there's results for the search
- if (have_posts()) :
- // Total results found
- $total_found = $wp_query->found_posts;
- // Last possible item on page
- $last_on_page = $paged * $posts_per_page;
- // First item on page
- $first_on_page = ($last_on_page - $posts_per_page) + 1;
- // If last possible item is more then total found, then the total is the last item for this page (the last page)
- if($total_found < $last_on_page) {
- // Last page
- $results_now = $first_on_page .' - '. $total_found;
- // EXAMPLE: 5-8 of 8
- }
- else {
- // Any other page
- $results_now = $first_on_page .' - '. $last_on_page;
- // EXAMPLE: 1-5 of 8
- }
- ?>
- <h2 class="pagetitle">Search Results</h2>
- <?php posts_nav_link(' ','< Previous','Next >'); ?>
- <?php while (have_posts()) : the_post(); ?>
- <div class="post_entry">
- <div class="post-thumb"><?php the_post_thumbnail('single-post-thumbnail'); ?></div>
- <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>
- <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>
- <?php
- $location = get_post_meta($post->ID, 'location', TRUE);
- $organization = get_post_meta($post->ID, 'organization', TRUE);
- $url = get_post_meta($post->ID, 'url', TRUE);
- ?>
- <div class="post-meta">
- <?php if($organization != ''){ ?><p class="post_meta_organization"><?php echo $organization; ?></p><?php } ?>
- <?php if($location != ''){ ?><p class="post_meta_location"><?php echo $location; ?></p><?php } ?>
- <?php if($url != ''){ ?><p class="post_meta_url">Website: <a href="<?php echo $url; ?>">Click Here</a></p><?php } ?>
- </div>
- <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>
- <p class="post_excerpt"><?php the_excerpt(); ?></p>
- <?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
- <?php comments_template( '', true ); ?>
- </div>
- <?php endwhile; ?>
- <div style="text-align:center">
- <?php posts_nav_link(' ','< Previous','Next >'); ?>
- </div>
- <?php else : ?>
- <h2 class="center">No posts or pages matched the search.</h2>
- <br />
- <?php endif; ?>
- </div>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement