Custom no results search page
-
Hi there and many thanks in advance for any help with my issue here:
In summary:
My theme is loading the “content-none.php” to display the search results and the search with “no results“. The 404 page was also being served from this page, but I have since removed it from there and customized the 404 the template. I’ve put the html divs in there and it’s working fine, in full width, as in the other theme pages. Just to be clear, the pages are all full width in the theme, except the Blog page which has the side bar.
The content-none.php page has the following:
*/ ?> <section class="no-results not-found"> <header class="page-header"> <h3 class="page-title"><?php _e( '' ); ?></h3> </header><!-- .page-header --> <div class="page-content"> <?php if ( is_home() && current_user_can( 'publish_posts' ) ) : ?> <p><?php printf( __( 'Ready to publish your first post? <a href="https://www.mywebsite">Get started here</a>.', 'wpzoom' ), esc_url( admin_url( 'post-new.php' ) ) ); ?></p> <?php elseif ( is_search() ) : ?> <h3 class="search-title"> <?php echo $wp_query->found_posts; ?> <?php _e( 'Search results found for', 'locale' ); ?>: "<?php the_search_query(); ?>" </h3> <?php get_search_form(); ?> <?php else : ?> <?php get_search_form(); ?> <?php endif; ?>
The problem:
When people search for a term in my website and they get “no results” however the page is inheriting the styling and the h1 from the “blog” page and I haven’t found a way to override this. I’ve tried calling in the divs and CSS that work in the 404 page, but it doesn’t go full width.
Please not that I want the “search results” to display the results as in the blog page, meaning that IS NOT full width. I only want it to be full width when the “search” query doesn’t find any matching term.
I’ve created a page named “no-results.php” and all the HTML that I need is there, but how can I tell the system not to load the blog styling and accept the full width?
This is the code from the no-results.php that I’ve created:
<?php /* Template Name: Search */ ?> <?php get_header(); ?> <main id="main" class="site-main" role="main"> <?php get_search_form(); ?> <?php if ( option::is_on( 'featured_posts_show' ) ) : ?> <?php endif; ?> <div class="widgetized-section"> <h2 class="section-title"></h2> <?php if ( ! function_exists( 'dynamic_sidebar' ) || ! dynamic_sidebar( 'home-full' ) ) : ?> <?php endif; ?> </div> </main><!-- #main --> <?php get_footer(); ?>
What’s on the CSS that I’m not being able to override:
.recent-posts { max-width: 970px; margin: 0 auto; padding: 0 10px; }
When I inspect the element in Chrome I can see that is wrapped in a section named:
<section class="recent-posts">
. This affects the search results and no results pages as wells as the blog. So, I can I override just one?Many thanks in advance for your help.
- The topic ‘Custom no results search page’ is closed to new replies.