You all know i had a theme change about a week ago. This theme is great and i really love it. As it seems you guys love it too. Anyways, since day one i noticed there is no search field nowhere in the theme. That was a pretty strange fact i hadn’t seen in any theme i’ve seen and tried out before. I didn’t really care much in the beginning since i can search from the admin area and i really thought that you guys, my readers, wouldn’t really need the search function. I was mistaken. My friend and loyal reader Giwrgos (George) came back to me with a comment about the missing search functionality. As he is a techy guy himself, he was able to pull out a search the hard way, but, i was troubled about how any other non techish guy could do it. So i started considering my various options.
For starters i could add a search field somewhere in the theme. That was not really an option since i am not that good on designing and i could really mess up the look and feel of the site (something i’d hate to do since i really like this look). And here is what i came up with.
I created a page that has a small search form. If you notice the menu there is a search link that leads to that page. Now, for you to get a grasp about it, all we need to do is create a link that has the form:
This can be easily done. All we need is a small form that submits data to the root URL of our blog using a get method. Here is the code:
<form action="/" method="get"> <input type="text" name="s"> <input type="submit" value="Search"> </form>
This is a very simple form but i need you to notice a couple of things:
- The “action” parameter on the form element tells where the form must be submitted. Now, if your blog resides on a top level domain, for example “http://www.yoursite.com” then this is just fine. Though, if your site is on a subfolder, for example the URL is “http://www.yoursite.com/blog/” then the action parameter needs to be set accordingly. For the previous example it should be: “action=’/blog/’“. Please notice that a subdomain is the same thing as a top level. I mean, if you site is “http://blog.yoursite.com” your don’t need to modify the action parameter.
- The “name” parameter on the input text element is “s”. This is the name of the variable on the search link given above.
Now to use this form all you need to do is the following:
- Create a new page.
- Write a small text telling the users that this page is to search content blah-blah.
- Go to the HTML tab.
- Copy-paste the form there.
- Hit save and publish!
Easy huh? That’s the point here… I hope i covered the subject pretty thouroughly and in enough detail in order for you to be able to do it easily yourselves. If, for any reason you have a problem or a comment, as always, i’ll be glad to hear about it!
I don’t think you would have messed up your layout by adding it to the sidebar. Does your theme use widgets?
That being said – this is good tutorial on making a separate search page.
@Kim: I thought about a widget but it would need some customization on coloring and stuff and a) i’m not that good at that and b) i’m a lazyass 🙂 So the page seemed like a good solution… As for the separate page i think that in general it’s a good idea to support it…
why a widget would need coloring? If your theme supports widgeted sidebar, you must be able to put in the code for search if I am not wrong.
@Raju: Well you are right but i would need to style the textbox and the button. Plus i have a very long sidebar i don’t want it to grow… i am looking for ways to shrink it a little bit…
How about having it as part of the header (floating right) next to wp-plugins)?