Since revision 342, Textpattern handles searching in a different way. A few people seem to be having problems with this, so here’s a quick howto.
In order for searches to work, there has to be a <txp:article /> tag on the page that’s used to display the results. By default the search input form will use the front page to display searches. If you don’t have a <txp:article /> tag on your front page, the best way to handle searches is to use a separate section to display the results:
1. Create a new page template, named search_page. You can use your standard layout by copying an existing template, but make sure that it includes a <txp:article /> tag. This is the page that will be used to display the results.
2. Create a new section named search (or some other name, if you’d prefer). Uses page should be set to search_page. Selected by default, On front page, Syndicate and Include in site search should all be set to no.
3. On all other page templates where you include a search input form, change the code to point to your new section:
<txp:search_input section="search" />
The rev 342 updates allow complete control over the display of the search results. You can use the following tags in your search_results form:
<txp:search_result_title />
<txp:search_result_excerpt />
<txp:search_result_url />
<txp:search_result_date />
..plus all the usual article tags like <txp:excerpt />, <txp:posted /> and so on. And on your search_page template:
<txp:search_result_count />
One thing to be aware of: <txp:search_result_count /> won’t work if it’s placed before the <txp:article /> tag on the page template. That’s because the search is performed by the <txp:article /> tag, so the number of results aren’t known before then. Fortunately, there is a way to overcome this. The pgonly attribute tells the article tag to do all the counts for pagination and search, but not display anything. By using the article tag twice, once with pgonly and once without, we can display the search result count at the top of the list:
<txp:article limit=25 pgonly=1 />
<txp:search_result_count />
<txp:article limit=25 />
The same principle isn’t limited to search results, and applies to pagination tags also. It’s important that both article tags have the same attributes (other than pgonly), otherwise the counts won’t match the list displayed by the second tag.
If you’re displaying search results on your main page, experiment with the <txp:if_search> </txp:if_search> tag. You might also find the <txp:article searchform="mysearchform" /> attribute helpful.
One benefit of the new system is that any pagination tags that work with <txp:article />, such as <txp:older> and <txp:newer>, can be used to page through search results. Set the number of results to display using the <txp:article limit=n /> attribute on your search_page template.
22 May 2005, 05:00 by Alex ·
Commenting is closed for this article.
Alex is a software developer from Melbourne, Australia. Threshold State is his consulting business.
“Labor is committed to introducing mandatory ISP filtering.” – Stephen Conroy, the new Communications Minister.
An excellent, minimal text editor for Windows.
All *.wordpress.com blogs have been blocked in Turkey – apparently because of one person, Turkish creationist Adnan Oktar.
The Opera browser team measured the percentage of people who use certain features. Several popular feature requests turned out to be unused, or almost so.
One thing I noticed: txp:search_result_count displays “articles found” without any number before it.
And: does the section have to be called “search” or could I give it its Germany equivalent name?
— andreas May 22, 07:33 pm #
txp:search_result_countdoesn’t display any number (for my query, there should be 10 articles).While playing a bit with this, I tried pagination.
txp:article limit="5". The links ‘work’ (prev, next), but a second page returns nil and zero, whereas it should displays 3 articles. But maybe that is because I use a definition list to wrap the search results. Need to play some more.— Philippe May 22, 11:40 pm #
search_result_countdoes work, but there’s a trick required to get it to display properly before the search results. I’ve updated the article to reflect this.There’s nothing special about the ‘search’ section – the magic is all done by the @@ tag, so you can use any section name you like.
— Alex May 23, 02:04 am #
‹txp:article pgonly=1 /›‹txp:search_result_count /›‹txp:article /›— andrew May 23, 02:13 am #
— andreas May 24, 11:37 pm #
Is it possible to limit the number of articles searched with a “Previous Page” “Next Page” link at the bottom. Similar to what we have with a standard articles page.
btw… I’m using a separate search page from default.
— Ray May 25, 06:44 am #
— Kjell May 25, 07:55 am #
to display in search-results the searchterm use Tag
txp:q.— Ingo Jun 13, 06:41 pm #
— Els Jun 28, 07:43 am #
— matt mikulla Aug 6, 10:51 pm #
I would like to make the comment, though, that where you say:
“3. On all other page templates where you include a search input form…”
You should remove the word “other”. I read this and it seemed that the search form I had on my new search_page was exempt from this tag syntax. I beat my head on the table for a few hours until I decided to try that on the form and it worked!
Thanks for the write up! I appreciate it. :)
— Yazmin Aug 10, 01:35 am #
— marios Mar 2, 08:17 am #
Hi!
I am trying to configure my search result page.
I cannot get the search results to display as a list. Even if I know that there are seven articles containing my search word only one is shown. What should I do? Thank you = )
— Jeannette Aug 18, 09:05 pm #