Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Sort search results?
Is there a tag (or attribute) to change the sorting order of search results? Right now they show up from oldest to newest posts, I want to reverse that order.
Thanks!
Offline
#2 2008-03-19 10:50:03
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Sort search results?
<txp:if_search>
<txp:article sort="posted desc" />
<txp:else />
<txp:article sort="posted asc" />
</txp:if_search>
…or however you want it :)
Offline
Re: Sort search results?
Well, I’m not sure where to put that…
Right now I have a “default” page and “default” form. Those two are used in 99% of the site (all blogposts, etc). I also have a “search_results” form, which contains pretty much the same code as in an article list, except there’s <p><txp:search_result_excerpt /></p>
instead of the usual <txp:excerpt /><txp:body />
stuff.
If I add an <txp:if_search> <txp:article sort="posted desc" /> </txp:if_search>
to the “search_results” form – there’s no difference in the output, so I suppose that’s not the proper place to put it.
ps:
I’ve added
<txp:if_search> <h2>Search results</h2> <p>some text here</p> <txp:article sort=“posted desc” /> </txp:if_search>
to the “default” PAGE and that works fine – it shows what I need where I needed in the correct order. However, I still get the other search results below, so I see double results – once from the “default” page and one from the “search_results” form… :/
Last edited by Boby Dimitrov (2008-03-19 13:41:48)
Offline
Re: Sort search results?
Bobby, I think you are having problems because the search is in “default” mode and is thus using your default section to display results. I believe that your best method to achieve the results you want is to use a separate “search” section and add <txp:if_section name="search">
tags to your default page template. You could then use something like <txp:article form="search_results" sort="posted desc" />
in between the “if_section” tags. You would also need to modify your search tag so that it points to the new section so something like:-
<form id="searchForm" method="get" action="<txp:site_url />search">
<p><input id="searchInput" type="text" name="q" value="" size="25" /><br /><input id="searchButton" type="submit" value="Go" /></p>
</form>
Last edited by thebombsite (2008-03-19 16:00:28)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: Sort search results?
Thanks for your tips, Stuart!
I’ve created a “search” section, edited the “search_results” form to be to my liking and added <txp:if_section name=“search”> to the “default” page template. So far, so good.
About the search form – what I use is a single input field (no button) called with <txp:search_input label="Search" wraptag="" />
. Now I’ve added section="search"
and that effectively changed the action of the form to mydomain.com/search/. I type some text in, hit enter and it searches, then shows results.
The problem is I still get double results. First (above) I get the properly ordered (sort="posted desc"
) articles and below them I get the same, but obviously sort="posted desc"
. You said that “the search is in “default” mode” – well, how do I turn that mode off?
What’s more, the “doubled” results are using the same “search_results”, obviously – I make a change in the form and it reflects on both result sets…
Offline
Re: Sort search results?
I think what is happening Boby is that the results obviously appear for the <txp:if_section name=search>
block but are being repeated because your other code in the template is not specific, that is to say, any section can use it. You probably need to use the <txp:else />
tag to exclude the “search” section from your other code so something like:-
<txp:if_section name="search">
<txp:article form="search_results" sort="posted desc" />
<txp:else />
<the article tag used by your other sections />
</txp:if_section>
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: Sort search results?
Well that solved the problem! Thanks once again, Stuart!
Offline
Pages: 1