The Movable Type User Manual

NOTE: This documentation is for Movable Type 3.2. If you are using a newer version, please see the documentation for Movable type 3.3x or Movable Type Enterprise.

« Creating a Search Form | Up | Adding Alternate Search Templates »

Chapter 10: Search

Customize the Default Search Template

Problem

You want to customize the look of your search engine results.

Solution

Edit the default.tmpl file in the search_templates directory.

Discussion

MT provides a handful of search tags which are only recognized in these special templates. Let's take a look at those tags and their usage:

  • MTSearchResults

    Similar to MTGoogleSearch, MTSearchResults is a container tag that creates the search results context and loops through each of the returned items. This tag creates an entry context so that any of the MTEntry tags will be valid. The search also creates a blog context for the entry so that any MTBlog tags can be used.

  • MTSearchResultCount

    The number of results found across all of the weblogs searched.

  • MTNoSearchResults

    A container tag whose contents are displayed if a search is performed but no results are found.

  • MTNoSearch

    A container tag whose contents are displayed only if there is no search performed. This is the case if a visitor were to go directly to your script (perhaps through a bookmark) without submitting any parameters through a form or query string. A good use for this tag might be to display some explanatory text search instructions or a more advanced search form.

  • MTBlogResultHeader

    When displaying standard search results, the results are grouped by the weblog in which they were found. This container tag's contents are displayed if the result in context is the first result in the weblog grouping. This is useful for displaying the name of the weblog, and perhaps a link to the main index for the weblog.

  • MTEntryEditLink

    This is a utility tag for providing authors with an alternate means of editing a link within MT. This tag creates a link to edit the entry represented by the search result, if the user displaying the search results page is logged in to Movable Type and has permission to edit the entry listed.

  • MTSearchString

    An HTML-encoded search query.

With these tags we can assemble our template. Here is a sample template.

 <MTNoSearch>
 <h2>Instructions</h2>
 <p>Blah blah blah....</p>
 </MTNoSearch>
 <MTNoSearchResults>
 <h2>Searched for "<$MTSearchString$>"</h2>
 <p>No pages were found containing "<$MTSearchString$>".</p>
 </MTNoSearchResults>
 <MTSearchResults>
 <MTBlogResultHeader><h2>Results from <$MTBlogName$></h2></MTBlogResultHeader>
 <h3><a href="<$MTEntryLink$>#<$MTEntryID pad="1"$>"><$MTEntryTitle$></a></h3>
 <p><$MTEntryExcerpt$> <$MTEntryEditLink$><br />
 <div class="posted">Posted in <$MTBlogName$> on <$MTEntryDate$></div>
 </p>
 </MTSearchResults>
 

See also Default Search Template Changes in the Knowledge Base.

Submit Feedback on This Article

Your comments on how we can improve this article are appreciated; but please do not use the feedback form to submit support requests or question. We will not respond to or publish such queries submitted through this form. If you have a technical question or problem, visit Movable Type Support.

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.
This website is powered by Movable Type.