On my site, editors can upload “banner” images to every page on the site. However, I’m having trouble figuring out how to link the search results page to a back-end page (ie the page that appears at example.com/?s=searchterm).
Does anyone have any tips on making a page in the back-end “link up” to the search results page so a user could upload a banner to a page in the back-end admin and have it appear on the search results page?
I did some googling and found this page on WordPress’ codex: http://codex.wordpress.org/Creating_a_Search_Page however the methods described there don’t seem to be working.
Any help would be appreciated.
So, if I understand well, you want to use a specific page as search results page.
This is a bit tricky, because when you are on search page, current query is the one created by the search term in the url, but to get a specific page you need a query for that page.
So you need 2 queries. This is not ideal about performance, and probably using a different way to link banner to pages you can solve this problem in a more efficent way.
However, let’s answer you question.
When you are in search result page WordPress uses the
search.php
template to show the results. See WordPress template hierarchy.If
search.php
is not there, your theme is usingindex.php
to show search results, in this case duplicate theindex.php
renaming the copysearch.php
: in this way you have a specific template for search results.If you are using a theme developed by third party, is a good idea doing everything in a child theme, in this way when you update theme you’ll not lose the changes.
You don’t say how you are linking banner to pages, I assume you upload banners as featured images, if you do it differently (e.g. using custom fields), edit the code accordingly.
Open your
search.php
and where you want to show the banner use:Now, you have to go in your dashboard, create a page and assign it the slug ‘search’. That slug is assigned automatically if you use ‘Search’ as title.
Finally add the banner to that page.