Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * The template for displaying search results pages.
- *
- *
- */
- global $query_string;
- global $wp_query;
- $search_query = wp_parse_str( $query_string, $array );
- $search = new WP_Query( $search_query );
- $total_results = $wp_query->found_posts;
- // Create dummy post (not in database) to avoid error messages due to NULL post object
- if ( $total_results == 0 ) {
- global $post;
- // WP_Post constructor
- function __construct( $post ) {
- foreach ( get_object_vars( $post ) as $key => $value )
- $this->$key = $value;
- }
- // set up attributes for this dummy post
- $post_id = -99; // negative ID, to avoid clash with a valid post
- $post = new stdClass();
- $post->ID = $post_id;
- $post->post_author = 1;
- $post->post_date = current_time( 'mysql' );
- $post->post_date_gmt = current_time( 'mysql', 1 );
- $post->post_title = 'Some dummy title';
- $post->post_content = 'Some dummy content';
- $post->post_status = 'publish';
- $post->comment_status = 'open';
- $post->post_name = 'fake-page-' . rand( 1, 99999 ); // append random number to avoid clash
- $post->post_type = 'page';
- $post->filter = 'raw'; // important!
- // Note: this gets rid of auto-pagination errors, but introduces comment-template notice that I can't seem to fix (Notice: Trying to get property of non-object in /var/www/html/wp-includes/comment-template.php on line 1196), which I believe refers to $post, which is now this dummy instead of some null post
- }
- // End dummy post creation
- get_header(); ?>
- <div class="search-container">
- <section id="primary" class="content-area">
- <main id="main" class="site-main" role="main">
- <div class="search-page-form" id="ss-search-page-form"><?php get_search_form(); ?></div>
- <header class="page-header">
- <div class="search-page-title"><b>You searched for: </b><?php echo get_search_query(); ?></div>
- <div class="number-results">We found <?php echo $total_results ?> results.</div>
- </header><!-- .page-header -->
- <?php if ( have_posts() ) : ?>
- <?php /* Start the Loop */ ?>
- <?php while ( have_posts() ) : the_post(); ?>
- <?php
- global $post;
- $image = get_the_post_thumbnail_url( $post->ID, 'medium-large-size' );
- if( empty( $image ) )
- {
- $image = get_stylesheet_directory_uri()."/images/default.png";
- }
- ?>
- <div class="single-result-item">
- <div class="results-featured-image"><a href="<?php the_permalink(); ?>"><img src="<?php echo $image ?>" ></a></div>
- <div class="results-item-wrapper">
- <h3 class="search-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
- <div class="search-post-excerpt"><?php the_excerpt(); ?></div>
- <div class="button-wrapper"><button class="search-post-link"><a href="<?php the_permalink(); ?>">Read More</a></button></div>
- </div>
- </div>
- <?php endwhile; ?>
- <?php base_pagination(); ?>
- <?php wp_reset_postdata(); // added this to bring query back if multiple queries are desired ?>
- <?php else : ?>
- <?php get_template_part( 'template-parts/content', 'none' ); ?>
- <div class="archive-page">
- <br clear="all">
- <p>However, you might be interested in checking out these recent posts:</p>
- <h3>Recent Posts</h3>
- <?php echo do_shortcode('[display-posts post_type="waterfalls,post,userwaterfallreview" posts_per_page="25" orderby="date" order="DESC" image_size="medium" wrapper="div" include_author="true" include_date="true" date_format="F j, Y g:i a" include_excerpt="true" excerpt_length="55" excerpt_more="...Read More" excerpt_more_link="true" default_image="75483"]'); ?>
- </div><!-- end .archive-page -->
- <?php endif; ?>
- </main><!-- #main -->
- </section><!-- #primary -->
- </div>
- <?php //get_sidebar(); ?>
- <?php get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement