1

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.

2
  • Probably it's me, but I don't really understand what you want to achieve. Can you give an example?
    – gmazzap
    Nov 23, 2013 at 20:29
  • @G.M. Sure, similar to what I said in the original post, let's say you have a site where an admin can upload a unique banner image to every single page on the site. How do you give them a page in the back-end where they can upload a banner that will appear on the search results page?
    – John
    Nov 24, 2013 at 18:40

1 Answer 1

0

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 using index.php to show search results, in this case duplicate the index.php renaming the copy search.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:

global $post;
$post = get_page_by_path('search');
setup_postdata($post);
// now the page with slug 'search' is treated as it was the current page
// so retrieve the banner just like you do in normal page
// I'll use page featured image
the_post_thumbnail();
wp_reset_postdata();

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.