How to create a search page in wordpress ?

Search facility in wordpress is an essential part of every blog. While creating a theme you need to create a search.php page. This is where all the search results are shown. You have to keep the name of file “search.php” if you are using inbuilt search form. Here we are going to discuss this topic for inbuilt search form results.

How to create a search form in wordpress?

First of all you need a search form on a page or sidebar of each page or header of the website. Doesn’t matter where it is. If you are using a widget, you don’t have to worry about search form coding. But if you want to use it a place where widgets can’t be used, try this.

Create a searchform.php file in your theme folder. Place the following php code in it and save it.

Now use the below mentioned code where you want this form to appear.

After following above two steps you will see a search input and a search button. This is your search form. Now we need to add code into search.php page.

How to show search results ?

To show search results for a particular keyword, paste the following code in your search.php page. After pasting the code you will see the search results, if any.

Please note if you have not created a searchform.php page, above code will show an error related to this page. If you don’t want search box to appear in search results page, deleteĀ <?php include (TEMPLATEPATH . ‘/searchform.php’); ?> from above code. This search box appears only if there are no results for a searched keyword.

I hope it helps. If it doesn’t, let me know via comments.

Happy Coding!



Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: