Search results for article titles

This tip features a method for styling search results if the search term was found in the title of the article, as requested by Joop Vos in a forum thread.

At this time, Textpattern does not offer a conditional tag like <txp:if_search_result_only_in_article_title>, but we can get around this with the use of the variable tag.

The code we need

<txp:variable name="body_result" value='<txp:search_result_excerpt />' />
<txp:if_variable name="body_result" value="">
     <p>The search term was found only in the article title.</p><!-- or leave empty -->
<txp:else />
     <p>"<txp:search_result_excerpt limit="99" hilight="strong" break="&hellip;" />"</p>
</txp:if_variable> 

We can see the result of this code by visiting Joop’s site using the following search term – the search result is telling us that the search term “prettige” was found in the title of the article.

comments powered by Disqus