Search results Sidebar

Hi all,

Instead of showing the error message IF there are no search results to display

<?php _e('Sorry, no results were found.', 'sage'); ?>

I would like to display a “no-results” template without sidebar…

I have edited the search.php file in the theme’s root directory to make it grab a custom template:

<?php if (!have_posts()) : ?> <?php get_template_part('templates/content', 'search-noresults'); ?> <?php endif; ?>

Could you please tell me how I can remove the sidebar from this template?
As the template resides in the /templates directory instead of the root directory, I’m afraid I cant use the is_page_template conditional tag in setup.php. Is there any other condtional tag I can use or how could this be done?

Thanks in advance!

Use is_search() for all search results pages, or is_search() && !have_posts() for only search results pages without any results.

There might be a helper function that already checks that more elegantly, but I’m on my phone and just writing from memory.

This seems to work @QWp6t! Thank you very much!