Forums › Forums › Search & Filter Pro › Custom message on infinite scroll search no results
- This topic has 2 replies, 2 voices, and was last updated 6 years, 5 months ago by Trevor.
Viewing 3 posts - 1 through 3 (of 3 total)
-
Anonymous(Private) June 13, 2018 at 8:54 pm #180311
How can I set up a custom message when search returns 0 results?
Site: Click here
My code:
<?php global $searchandfilter; $atrair_home = $searchandfilter->get(180)->current_query(); if ((!$atrair_home->is_filtered())&&($atrair_home->get_search_term()=="")) { $args = array( 'post_type' => array( 'post', 'ebooks', 'podcasts', 'videos' ), 'post_status' => 'publish', ); $posts = new WP_Query( $args ); if( $posts->have_posts() ) : ?> <?php while( $posts->have_posts() ) : $posts->the_post(); ?> <div class="posts-double"> <?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?> <a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark"> <?php $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'thumbnail'); echo '<div class="image" style="background:url('.esc_url($featured_img_url).')"></div>' ?> <?php endif; ?> </a> <div class="content"> <a class="title" href="<?php the_permalink() ?>" rel="bookmark"> <?php the_title(); ?> </a> <p class="descriptions"> <?php echo wp_trim_words( get_the_content(), 15, '...' );?> </p> <div class="related-post-category"> <?php the_tags(); $post_type = get_post_type(get_the_ID()); $post_name = get_post_type_object(get_post_type())->labels; if ( $post_type != 'post' ) { echo '<a href="'.get_post_type_archive_link( $post_type ).'"><span class="'.$post_type.'">'.$post_name->name.'</span></a>'; }; ?> </div> </div> <div class="posts-footer"> <div class="related-time"> <?php echo do_shortcode('[rt_reading_time]'); ?> </div> <div class="related-bookmark"> <?php echo do_shortcode('[cbxwpbookmarkbtn]'); ?> </div> </div> </div> <?php endwhile; wp_reset_postdata(); else : echo 'Não conseguimos encontrar nenhum resultado...'; endif; } else //Inicio fim { if ( $query->have_posts() ) { ?> Found <?php echo $query->found_posts; ?> Results<br /> <div class='search-filter-results-list'> <?php while ($query->have_posts()) { $query->the_post(); ?> <div class="posts-double"> <?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?> <a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark"> <?php $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'thumbnail'); echo '<div class="image" style="background:url('.esc_url($featured_img_url).')"></div>' ?> <?php endif; ?> </a> <div class="content"> <a class="title" href="<?php the_permalink() ?>" rel="bookmark"> <?php the_title(); ?> </a> <p class="descriptions"> <?php echo wp_trim_words( get_the_content(), 15, '...' );?> </p> <div class="related-post-category"> <?php the_tags(); $post_type = get_post_type(get_the_ID()); $post_name = get_post_type_object(get_post_type())->labels; if ( $post_type != 'post' ) { echo '<a href="'.get_post_type_archive_link( $post_type ).'"><span class="'.$post_type.'">'.$post_name->name.'</span></a>'; }; ?> </div> </div> <div class="posts-footer"> <div class="related-time"> <?php echo do_shortcode('[rt_reading_time]'); ?> </div> <div class="related-bookmark"> <?php echo do_shortcode('[cbxwpbookmarkbtn]'); ?> </div> </div> </div> <?php } ?> </div> <?php } else { ?> <div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'> <span>End of Results</span> </div> <?php } } ?>
Trevor(Private) June 14, 2018 at 11:19 am #180335This is our standard infinite scroll results.php template modified to have a no results message. Use this as a starting point:
<?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 * */ if ( $query->have_posts() ) { ?> Found <?php echo $query->found_posts; ?> Results<br /> <div class='search-filter-results-list'> <?php while ($query->have_posts()) { $query->the_post(); ?> <div class='search-filter-result-item'> <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> <hr /> </div> <?php } ?> </div> <?php } else { //figure out which type of "no results" message to show $message = "noresults"; if(isset($query->query['paged'])) { if($query->query['paged']>1){ $message = "endofresults"; } } if($message=="noresults") { ?> <div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'> <span>No Results Found</span> </div> <?php } else { ?> <div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'> <span>End of Results</span> </div> <?php } } ?>
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)