Search Results Tag

The Search Results Tag controls how you display results from your searches. Example:

<table border="0" cellpadding="6" cellspacing="1" width="100%">
<tr>
<th>{lang:title}</th>
<th>{lang:excerpt}</th>
<th>{lang:author}</th>
<th>{lang:date}</th>
<th>{lang:total_comments}</th>
<th>{lang:recent_comments}</th>
</tr>

{exp:search:search_results switch="resultRowOne|resultRowTwo"}

<tr class="{switch}">
<td width="30%" valign="top"><b><a href="{auto_path}">{title}</a></b></td>
<td width="30%" valign="top">{excerpt}</td>
<td width="10%" valign="top"><a href="{member_path='member/index'}">{author}</a></td>
<td width="10%" valign="top">{entry_date format="%m/%d/%y"}</td>
<td width="10%" valign="top">{comment_total}</td>
<td width="10%" valign="top">{recent_comment_date format="%m/%d/%y"}</td>
</tr>

{/exp:search:search_results}

</table>

{if paginate}

<div class='paginate'>

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

</div>

{/if}

Parameters

backspace=

backspace="6"

Backspacing removes characters from the last iteration of the search results loop. For example, if you put a <br /> tag between each result you'll have this layout:

Entry 1 title<br />
Entry 2 title<br />
Entry 3 title<br />

You might, however, not want the <br /> tag after the final item. By adding backspacing you can remove it. Simply count the number of characters and spaces in the item you want to remove and add it to the tag. A <br /> tag has 6 characters, so you would do this:

{exp:search:search_results switch="resultRowOne|resultRowTwo" backspace="6" rdf="off"}

{title}<br />

{/exp:search:search_results}

That will produce code like this:

Entry 1 title<br />
Entry 2 title<br />
Entry 3 title

Note:  The "backspace" parameter will only work if you have either the rdf="off" parameter specified or you have "Add Trackback Auto-discovery code to your pages?" setting turned off under Weblog Management.

rdf=

rdf="off" rdf="on"

The Trackback Autodiscovery RDF code can be manually set for any particular weblog entry listing. This is useful when used on the RSS pages if the "global" setting in Weblog Management is turned on.

switch=

switch="option_one|option_two"

This parameter allows you to set two values that will alternate between the result rows. This is commonly used to have alternating colored backgrounds for the result rows. This parameter works in conjunction with the {switch} variable.

This is a legacy parameter, and has been replaced by the more advanced {switch=} variable from the Weblog Entries tag which has greater flexibility. This parameter / variable combo will continue to function, but it is recommended that the Weblog Entries tag's {switch=} variable be used.

Variables

{title}
{permalink}
{author}
{body}
et cetera...

Nearly all of the Weblog Entries Tag Variables are available for the search results page so that you can display as much or as little of the weblog entry's data as possible depending on your needs. There are also some search results specific variables available in the results page:

auto_path

{auto_path}

This parameter is replaced with the URL to the entry with the URL Title appended to the end. Unlike other "path" variables, this variable does not require the Template_Group/Template to be specified. Instead, the path will automatically be determined by the Weblog URL setting for the weblog in Weblog Management.

excerpt

{excerpt}

An excerpt from the entry. The excerpt consists of the first 50 words from the field specified for search excerpting in your Weblog Management settings for your weblogs. HTML markup is stripped prior to output.

full_text

{full_text}

The text from the entry. Unlike the {excerpt} variable, this one returns the entire text from the field specified for search excerpting in your Weblog Management settings for your weblogs.

id_auto_path

{id_auto_path}

This parameter is replaced with the URL to the entry with the Entry ID appended to the end. Unlike other "path" variables, this variable does not require the Template_Group/Template to be specified. Instead, the path will automatically be determined by the Weblog URL setting for the weblog in Weblog Management.

member_path

{member_path='member/index'}

The Template_Group/Template with which to display the member profile of the author of the entry. Typically, this variable will be specified as {member_path='member/index'}.

switch

{switch}

This variable is dynamically replaced by the appropriate value specified in the switch= parameter. This variable is commonly used to set a CSS class or a background color.

This is a legacy variable, and has been replaced by the more advanced {switch=} variable from the Weblog Entries tag which has greater flexibility. This parameter / variable combo will continue to function, but it is recommended that the Weblog Entries tag's {switch=} variable be used.

Top of Page

User Contributed Notes

Posted by: Daniel Walton on 7 September 2007 10:12am
Daniel Walton's avatar

Note: {auto_path} will return the url_title path defined by the weblog parameters regardless of if the entry has been defined as a ‘page’ within the pages module.

To correct this behaviour you could use something like:

{if page_url != ''}
<a href="{page_url}">{title}</a>
{if:else}
<a href="{auto_path}">{title}</a>
{/if}

Posted by: MediaGirl Inc. on 30 July 2007 11:44am
MediaGirl Inc.'s avatar

TIP: To show the search term and the total results found on the search results page, use the following:

Your search for {exp:search:keywords} found {exp:search:total_results}{total_results}{/exp:search:total_results} results.

You must have an ExpressionEngine license and have attained a forum rank of "Lab Assistant" (100 posts) to contribute notes to the User Guide