If Search Results Textpattern Plugin

While I was in the process of building the Mestolando site for Claudia and Brian, Brian had what I thought a simple request. When no search results were returned, the page was blank and he wanted a message saying that no results were found, yadda, yadda, yadda. I came to find that there was no way to do this in Textpattern 4.0.3.

As I scoured Google for an answer to my problem, I found this post that detailed how to to embed PHP code in your page template or form to get the job done. Looked easy enough…problem solved. I created the rss_if_search_results plugin to give you the same ability without the embedded PHP code. Here’s an example:

<txp:rss_if_search_results>
I have results
<txp:else>
I don't have results
</txp:rss_if_search_results>

There is also an <txp:rss_if_no_search_results> tag included just for fun.

Comments

10. August 2006

I used simple standard TXP tags and have this same functionality on my site.

I have a default message on the search page but if you do a search that message goes away and the results show up. No results yields a 0 results message.

I make my search form point to /search/. I then have a if_section name=search. Then I do a txp:if_search tag followed by a txp:article pgonly=”y”. Next I do a line that looks like this: Your query returned txp:search_result_count text=”” results… Then I call my article for the actual results. Finally I use the else tag and use my default message just in case someone tried to view the search page by typing in the /search/ url.

11. August 2006

That’s a nice solution Craig. I suppose the plugin might still be useful, but it’s always nice to use built in TXP tags if possible.

Rob

14. August 2006

Thank you for creating this useful plugin.
I tried to put it in the pages section search_input but nothing happened when I made my search. Where should I put in the conditional output so I can make it work?
Thank you!

17. September 2007

With its proven usefulness, it would have been a shame to exclude this functionality out of the Textpattern core.

So there it is, starting from Textpattern 4.0.6 (which is yet to be released at the time of this writing): txp:if_search_results.

Commenting is closed for this article.

Textpattern Solutions

Textpattern Solutions

Textpattern Solutions is the first book published on Textpattern.

details at friends of ED or the official book website.

buy it at amazon.com