Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Text output depending on number of search results
Is there there a way to have different text outputs depending on whether there is one result, multiple results or no results.
Examples:
1 item matches your search.
2 items match your search.
There is no match for your search.
Last edited by mwr (2024-11-01 23:46:17)
Mark
Offline
Re: Text output depending on number of search results
Absolutely :)
<if::search_results max="1">
1 item matches your search.
<txp:else />
<if::search_results>
<txp:search_results_count text="items" /> match your search.
<txp:else />
There is no match for your search.
</if::search_results>
</if::search_results>
NB: under 4.9.0+ the <txp:search_results_count />
tag has been deprecated and is now called the more generic <txp:items_count />
because it works in places outside of just search.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Text output depending on number of search results
Thanks, Bloke!
Going to assume you meant this:
<txp:if_search_results max=“1”> 1 item matches your search. <txp:else /> <txp:if_search_results> <txp:search_result_count text=“items” /> match your search. <txp:else /> There is no match for your search. </txp:if_search_results> </txp:if_search_results>Last edited by mwr (2024-11-02 03:57:58)
Mark
Offline
Re: Text output depending on number of search results
Same thing, yes. Up to you if you want to use the full txp: syntax or the shorthand. Depends on your settings, but it’s enabled by default.
I could have used <search::results_count />
too.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Text output depending on number of search results
Cool. I’ll have to learn more about shorthand.
Mark
Offline