The search feature was not going to be as kind as the pagination. This was a slightly more complicated process. Luckily at the beginning of the channel creation, I made sure that every entry on every channel was searchable. This was to make sure that I wouldn’t have to go back and check again.

The first stage was to create a new template group entitled: Search. In this group, I created two different templates. Both based on the template for blog, one would be a results page, and the other would be a (yep, you guessed it…) no results page.

Firstly, I created the no results page. As this page required no channels or tag pairs from EE and it simply had to relay a message describing how there were no results. As there is no EE code, you can see the template below:

(screenshots taken and updated 14/05/13)

search 1

The page simply displays ‘SORRY – NO RESULTS’ and a short apology message instructing the user to search again.

After this I opened the index page from this group.

To display search results, I had to use the {exp:search:search_results} tag pair. Inside these, I included {title}, {category}, {excerpt} – this takes 50 words from a chosen category to preview the entry, and {auto_path}. Auto_path was a new parameter that had to be coded so that it knew where to go from the ‘view post’ link.

search code

In channel preferences, I set the path for each single entry page for each channel.

search path

Finally, I had to add a search bar to my templates. I wanted this to be in the header so that users could choose to search as soon as they access a page, and don’t have to look for where the search bar is.

search bar code

I used the tag pair {exp:search:simple_form}, applied every channel to the search form, assigned the following attributes to link pages to results: no_result_page=”search/no_result” result_page=”search/index” search_in=”everywhere” and included a small form inside the tag pair. I styled this using CSS and now it looks like this:

search bar

I tested it a couple of times, but I forgot to add all of the channels initially so it wouldn’t work at first! Now I’ve fixed it though. As a trial, I will do a search for ‘Dolan’ – a word that I already know is associated with a gallery image, so lets see what happens:

search dolan

Good, it found it! And where does it link to…………..

search dolan result

Tada! Working search form.