brandnewbox.co.uk

Home of Andrew Weaver, a uk-based web developer specialised in building high-quality websites

A simple ExpressionEngine search page

Thursday, January 25th, 2007

Andrew Weaver

Category:

Expression Engine provides a handy search module that provides an easy mechanism for adding a search facility to your site.

This first article implements a simple search box and results page.

Create the search box

This is a simple variation of the Simple Search Form from the EE documentation. This could be put into its own template or more likely be part of a global header embedded into every page.

{assign_variable:my_weblog="default_site"}
{assign_variable
:my_template_group="site"}

{
!-- your page header --}

{exp
:search:simple_form weblog="{my_weblog}"}

<div class="row">
<
label for="keywords">Search:</label>
<
input type="text" class="text" name="keywords" id="keywords" value="" size="18" maxlength="100" />
</
div>

<
div class="row">
<
div class="spacer">&nbsp;</div>
<
input type="submit" class="button" value="Search" />
</
div>

{/exp:search:simple_form}

{
!-- your page footer --

An optional result_page=“search/results” can be added to the exp:search:simple_form tag to specify the search results page.

An example search box can be seen here.

The search results page

This will be in its own template (eg, search/results) wrapped in the site’s header and footer.

For usability we could include the search box again (with the search term filled in):

{!-- your page header --}

{exp
:search:simple_form weblog="{my_weblog}"}

<div class="row">
<
label for="keywords">Search:</label>
<
input type="text" class="text" name="keywords" id="keywords" value="{exp:search:keywords}" size="18" maxlength="100" />
</
div>

<
div class="row">
<
div class="spacer">&nbsp;</div>
<
input type="submit" class="button" value="Search" />
</
div>

{/exp:search:simple_form} 

Before displaying the results:

<p>Searching for: <b>{exp:search:keywords}</bfound {exp:search:total_results} results.</p>

{exp:search:search_results}

<dl>
<
dt><a href="{auto_path}">{title}</a></dt>
<
dd>{excerpt}</dd>
</
dl>

{/exp:search:search_results}

{if paginate}

<div class='paginate'>
<
span class='pagecount'>{page_count}</span>&nbsp{paginate}
</div>

{/if}

{
!-- your page header --

This will display the search results in a simple, definition list.

Comments

1. Sue Crocker
13th Jun 2007 at 11:57 am

I tried looking for expressionengine, since that’s the offical name of the product. :) No matches.

But I did find them when searching for expression engine.

2. .(JavaScript must be enabled to view this email address)
12th Dec 2007 at 11:42 pm

what happens if you have more than one weblog on your site and you want to search them all?

3. Yassir
16th Jan 2008 at 10:59 am

@steve
Easy. Just add this parameter search_in=“everywhere” to the {exp:search:simple_form} tag :)

4. User-Luser
1st Feb 2008 at 2:48 pm

I invite you to attend our new blog. Its maintenance for certain will interest you visitors.
We wait for you on the most fair blog:

http://blogaboutme12711.blogspot.com

http://blogaboutme98641.blogspot.com

http://blogaboutme38409.blogspot.com

Commenting is not available in this weblog entry.

© brandnewbox.co.uk 2004-2010