Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. <div class="search-cont">
  2. <form class="searchinput" method="get" action="<?php echo home_url(); ?>" role="search">
  3. <input type="search" class="searchinput" placeholder="<?php echo esc_attr_x( 'Click icon or hit enter to search..', 'placeholder' ) ?>" value="<?php get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
  4. <button type="submit" role="button" class="search-btn"/><i class="fa fa-search" aria-hidden="true"></i></button>
  5. </form>
  6. </div>
  7.  
  8. <div class="searchresultsbox">
  9. <?php global $wp_query;?>
  10. <h2> <?php echo $wp_query->found_posts; ?><?php _e( ' results found for', 'locale' ); ?>: "<?php the_search_query(); ?>"</h2>
  11. <?php if ( have_posts() ) { ?>
  12. <h3><?php printf( __( 'Your "%s" search results can be found at:', 'ptpisblogging' ), get_search_query() ); ?></h3>
  13. <?php while ( have_posts() ) { the_post(); ?>
  14. <h3><a href="<?php echo get_permalink(); ?>">
  15. <?php the_title(); ?>
  16. </a></h3>
  17. <?php //echo substr(get_the_excerpt(), 0, 2); ?>
  18. <div class="h-readmore"> <a href="<?php //the_permalink(); ?>"></a></div>
  19. <?php
  20. $args=array('s'=>'test','order'=> 'DESC', 'posts_per_page'=>get_option('posts_per_page'));
  21. $query=new WP_Query($args);
  22. if( $query->have_posts()):
  23. while( $query->have_posts()): $query->the_post();
  24. {
  25. echo $post->post_title;
  26. echo $post->post_content;
  27. }
  28. endwhile;
  29. else:
  30. endif;
  31. ?>
  32. <?php } ?>
  33. <?php paginate_links(); ?>
  34. <?php } ?>
  35. </div>
  36. </div>
  37. </div>
  38. <param name="" value="">
  39. </div><!-- /searchresultsbox -->
  40. </div><!-- /collcelltwo -->
  41. </div><!-- /tb-one-row -->
  42. </div><!-- /tb-one -->
  43.  
  44. add_action( 'pre_get_posts', function( $query ) {
  45. // Check that it is the query we want to change: front-end search query
  46. if( $query->is_main_query() && ! is_admin() && $query->is_search() ) {
  47. // Change the query parameters
  48. $query->set( 'posts_per_page', 4 );
  49. }
  50. } );
  51.  
  52. // $searchresult = result of search process,
  53. //$highlightword = word you want to highlight
  54. $searchresult = str_replace($highlightword,
  55. "<span style="background-color:#ffff00;">$highlightword</span>",
  56. $searchresult);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement