Forums › Forums › Search & Filter Pro › How to not show results in first search + translate "Older/ newer posts"
- This topic has 19 replies, 3 voices, and was last updated 8 years ago by Ross.
-
Anonymous(Private) November 2, 2016 at 5:11 pm #68154
[thread split from https://support.searchandfilter.com/forums/topic/how-to-not-show-results-in-first-search-translate-older-newer-posts/ by @trevorsf ]
Hi Trevor,
I’ve attempted to use this code (and the solutions from the other threads without any luck at all). I don’t want to start another thread with the same question because you’ve had to repeat yourself a few times. Hopefully this is OK.
I’m using the shortcode method for displaying my search and results. I tried the second piece of code from this thread: https://support.searchandfilter.com/forums/topic/how-do-i-hide-initial-results/page/2/#post-44951 but it displays all the items on load instead of hiding them until someone searches.
In this example you have a ! in “if (!$sf_current_query->is_filtered()) {” and say nothing should go in the brackets before the else statement. I’ve added the output part of the results.php but I’m not have any success.
Would it be possible to get an updated results.php example like you did in the other thread that will display nothing until the user searches and if they get no results it will display the message?
Trevor(Private) November 2, 2016 at 5:23 pm #68157Something like this:
<?php /** * Search & Filter Pro * * Sample Results Template * * @package Search_Filter * @author Ross Morsali * @link http://www.designsandcode.com/ * @copyright 2015 Designs & Code * * Note: these templates are not full page templates, rather * just an encaspulation of the your results loop which should * be inserted in to other pages by using a shortcode - think * of it as a template part * * This template is an absolute base example showing you what * you can do, for more customisation see the WordPress docs * and using template tags - * * http://codex.wordpress.org/Template_Tags * */ global $searchandfilter; $sf_current_query = $searchandfilter->get(1726)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>Nothing to see here folks!</div>'; } else { if ( $query->have_posts() ) { ?> Found <?php echo $query->found_posts; ?> Results<br /> Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br /> <div class="pagination"> <div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div> <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php /* example code for using the wp_pagenavi plugin */ if (function_exists('wp_pagenavi')) { echo "<br />"; wp_pagenavi( array( 'query' => $query ) ); } ?> </div> <?php while ($query->have_posts()) { $query->the_post(); ?> <div> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p><br /><?php the_excerpt(); ?></p> <?php if ( has_post_thumbnail() ) { echo '<p>'; the_post_thumbnail("small"); echo '</p>'; } ?> <p><?php the_category(); ?></p> <p><?php the_tags(); ?></p> <p><small><?php the_date(); ?></small></p> </div> <hr /> <?php } ?> Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br /> <div class="pagination"> <div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div> <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php /* example code for using the wp_pagenavi plugin */ if (function_exists('wp_pagenavi')) { echo "<br />"; wp_pagenavi( array( 'query' => $query ) ); } ?> </div> <?php } else { echo "No Results Found"; } } ?>
I think?
Anonymous(Private) November 2, 2016 at 5:33 pm #68159Thank you for the quick response!
However, it’s still not working for me.
http://brwbox.com/cms/test-page/
10001 is a valid search but it still displays the “Nothing to see here folks!”
Anonymous(Private) November 2, 2016 at 6:54 pm #68194I had to swap out the theme and switch the site back on for the client. I’m still looking for a solution to this.
The search functionality works great normally. It’s when I try to hide the initial search that it fails.
http://brwbox.com/cms/ – Buy Online
-
AuthorPosts