Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="search-cont">
- <form class="searchinput" method="get" action="<?php echo home_url(); ?>" role="search">
- <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' ) ?>" />
- <button type="submit" role="button" class="search-btn"/><i class="fa fa-search" aria-hidden="true"></i></button>
- </form>
- </div>
- <div class="searchresultsbox">
- <?php global $wp_query;?>
- <h2> <?php echo $wp_query->found_posts; ?><?php _e( ' results found for', 'locale' ); ?>: "<?php the_search_query(); ?>"</h2>
- <?php if ( have_posts() ) { ?>
- <h3><?php printf( __( 'Your "%s" search results can be found at:', 'ptpisblogging' ), get_search_query() ); ?></h3>
- <?php while ( have_posts() ) { the_post(); ?>
- <h3><a href="<?php echo get_permalink(); ?>">
- <?php the_title(); ?>
- </a></h3>
- <?php //echo substr(get_the_excerpt(), 0, 2); ?>
- <div class="h-readmore"> <a href="<?php //the_permalink(); ?>"></a></div>
- <?php
- $args=array('s'=>'test','order'=> 'DESC', 'posts_per_page'=>get_option('posts_per_page'));
- $query=new WP_Query($args);
- if( $query->have_posts()):
- while( $query->have_posts()): $query->the_post();
- {
- echo $post->post_title;
- echo $post->post_content;
- }
- endwhile;
- else:
- endif;
- ?>
- <?php } ?>
- <?php paginate_links(); ?>
- <?php } ?>
- </div>
- </div>
- </div>
- <param name="" value="">
- </div><!-- /searchresultsbox -->
- </div><!-- /collcelltwo -->
- </div><!-- /tb-one-row -->
- </div><!-- /tb-one -->
- add_action( 'pre_get_posts', function( $query ) {
- // Check that it is the query we want to change: front-end search query
- if( $query->is_main_query() && ! is_admin() && $query->is_search() ) {
- // Change the query parameters
- $query->set( 'posts_per_page', 4 );
- }
- } );
- // $searchresult = result of search process,
- //$highlightword = word you want to highlight
- $searchresult = str_replace($highlightword,
- "<span style="background-color:#ffff00;">$highlightword</span>",
- $searchresult);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement