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:
MTSearchResultsSimilar to
MTGoogleSearch,MTSearchResultsis 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 theMTEntrytags will be valid. The search also creates a blog context for the entry so that anyMTBlogtags can be used.MTSearchResultCountThe number of results found across all of the weblogs searched.
MTNoSearchResultsA container tag whose contents are displayed if a search is performed but no results are found.
MTNoSearchA 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.
MTBlogResultHeaderWhen 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.
MTEntryEditLinkThis 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.
MTSearchStringAn 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.



