Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2009-10-22 21:44:34
- timstr
- New Member
- Registered: 2006-12-14
- Posts: 6
Disabling search_results?
I’m using the following code to show my search results in a fancy format:
<txp:if_search>
<txp:article pgonly="1" />
<txp:if_search_results>
<txp:article searchform="fancy_search_results" />
<txp:else />
<p>Nothing found</p>
</txp:if_search_results>
</txp:if_search>
This works fine, but for some reason TXP also shows the results using the default search_results form, without me calling it.
In other words, search results show up twice on the same page.
How do I disable the default search_results form? (Deleting it doesn’t work, I get an error.)
Last edited by timstr (2009-10-22 21:46:02)
Offline
Re: Disabling search_results?
Are you specifying the new search form in your article tag?
search_form is the default.
Last edited by MattD (2009-10-22 22:20:12)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Disabling search_results?
timstr wrote:
This works fine, but for some reason TXP also shows the results using the default search_results form, without me calling it.
That usually happens if you have two <txp:article/>
calls. Please, post Tag Trace from the problem page and TXP version.
In addition, in your markup the first <txp:article/>
call (pgonly count), isn’t required.
<txp:if_search>
<txp:article searchform="fancy_search_results" />
<txp:if_search_results>
<txp:else />
<p>Nothing found</p>
</txp:if_search_results>
</txp:if_search>
Will do the same.
Last edited by Gocom (2009-10-23 00:05:23)
Offline
#4 2009-10-23 05:44:20
- timstr
- New Member
- Registered: 2006-12-14
- Posts: 6
Re: Disabling search_results?
Thanks for your replies!
I’ve changed my code to what Gocom suggested, but the problem persists.
Textpattern version is 4.2.0.
My code now is:
<txp:if_category>
<txp:article listform="list_articles_in_category" />
<txp:else />
<txp:if_search>
<txp:article searchform="fancy_search_results" />
<txp:if_search_results>
<txp:else />
<p>Nothing found</p>
</txp:if_search_results>
</txp:if_search>
<txp:if_individual_article>
<txp:article limit="1" />
<txp:else />
<txp:article limit="1" pageby="10" />
<txp:article listform="list_recent_articles" limit="9" offset="1" pageby="10" />
</txp:if_individual_article>
</txp:if_category>
txp tag trace for this is as follows:
<txp:if_category>
[<txp:if_category>: false]
<txp:if_search>
[<txp:if_search>: true]
<txp:article searchform="fancy_search_results" />
[SQL (0,00069379806518555): select name from txp_section where searchable != '1']
[SQL (0,00094318389892578): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (`Title` rlike 'test' or `Body` rlike 'test') ]
[SQL (0,0013961791992188): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod, match (`Title`, `Body`) against ('test') as score from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (`Title` rlike 'test' or `Body` rlike 'test') order by score desc limit 0, 10]
[artikel 2]
[SQL (0,0002739429473877): select Form from txp_form where name='fancy_search_results']
[Module: fancy_search_results]
<txp:if_first_article>
[<txp:if_first_article>: true]
<txp:page_url type="q" />
</txp:if_first_article>
<txp:posted />
<txp:permlink>
<txp:title />
</txp:permlink>
<txp:excerpt />
<txp:if_last_article>
[<txp:if_last_article>: false]
</txp:if_last_article>
[artikel 3]
[Module: fancy_search_results]
<txp:if_first_article>
[<txp:if_first_article>: false]
</txp:if_first_article>
<txp:posted />
<txp:permlink>
<txp:title />
</txp:permlink>
<txp:excerpt />
<txp:if_last_article>
[<txp:if_last_article>: false]
</txp:if_last_article>
[artikel 4]
[Module: fancy_search_results]
<txp:if_first_article>
[<txp:if_first_article>: false]
</txp:if_first_article>
<txp:posted />
<txp:permlink>
<txp:title />
</txp:permlink>
<txp:excerpt />
<txp:if_last_article>
[<txp:if_last_article>: true]
</txp:if_last_article>
<txp:if_search_results>
[<txp:if_search_results>: true]
</txp:if_search_results>
</txp:if_search>
<txp:if_individual_article>
[<txp:if_individual_article>: false]
<txp:article limit="1" pageby="10" />
[SQL (0,00031399726867676): select name from txp_section where searchable != '1']
[SQL (0,00050520896911621): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (`Title` rlike 'test' or `Body` rlike 'test') ]
[SQL (0,0011131763458252): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod, match (`Title`, `Body`) against ('test') as score from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (`Title` rlike 'test' or `Body` rlike 'test') order by score desc limit 0, 1]
[artikel 2]
[SQL (0,00025010108947754): select Form from txp_form where name='search_results']
[Module: search_results]
<txp:article listform="list_recent_articles" limit="9" offset="1" pageby="10" />
[SQL (0,00027298927307129): select name from txp_section where searchable != '1']
[SQL (0,00050210952758789): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (`Title` rlike 'test' or `Body` rlike 'test') ]
[SQL (0,0012140274047852): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod, match (`Title`, `Body`) against ('test') as score from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = '0000-00-00 00:00:00') and (`Title` rlike 'test' or `Body` rlike 'test') order by score desc limit 1, 9]
[artikel 3]
[Module: search_results]
[artikel 4]
[Module: search_results]
</txp:if_individual_article>
</txp:if_category>
Last edited by timstr (2009-10-23 05:44:51)
Offline
#5 2009-10-23 05:55:14
- timstr
- New Member
- Registered: 2006-12-14
- Posts: 6
Re: Disabling search_results?
Looking at my tags out of context, I realized this may be the proper way to do things:
<txp:if_category>
<txp:article listform="list_articles_in_category" />
<txp:else />
<txp:if_search>
<txp:article searchform="fancy_search_results" />
<txp:if_search_results>
<txp:else />
<p>Nothing found</p>
</txp:if_search_results>
<txp:else />
<txp:if_individual_article>
<txp:article limit="1" />
<txp:else />
<txp:article limit="1" pageby="10" />
<txp:article listform="list_recent_articles" limit="9" offset="1" pageby="10" />
</txp:if_individual_article>
</txp:if_search>
</txp:if_category>
This seems to fix the double-search results problem.
Could you comfirm that this is indeed the right way to branch category > search > individual_article?
Offline
Re: Disabling search_results?
timstr wrote:
Could you comfirm that this is indeed the right way to branch category > search > individual_article?
Well there are a multitude of ways to go about it, but that seems pretty logical to me!
What always used to catch me out is that any call to <txp:article>
in your default page template when q=
is in the URL triggers search results via the search_form
form. Since txp:article is clever and is automatically context sensitive, it doesn’t matter whether you use if_search
or not — that’s just a convenience function :-s
Thus, as you found in your original code, inside your if_search you had a call to <txp:article searchform="fancy_search_results" />
which rendered the search results. Then TXP encountered the <txp:if_individual_article>
, decided it was in “list mode” (a search list!) and executed the ‘else’ branch, which saw another <txp:article>
tag. Since this one didn’t have a searchform
attribute, it used the default form to render the searched articles a second time.
If you were doing a normal article list, you could perhaps simplify your code by only employing one article tag and using the <txp:if_search> conditional to just alter the heading. e.g.:
<txp:if_category>
<h2><txp:category title="1" /></h2>
<txp:article listform="list_articles_in_category" />
<txp:else />
<txp:if_search>
<h2><txp:text item="search_results" />: <txp:page_url type="q" /></h2>
</txp:if_search>
<txp:article limit="5" listform="list_recent_articles" searchform="fancy_search_results" />
</txp:if_category>
The downside here is that you wouldn’t get your fancy split of highlighting the first article and then listing the remainder via the offset
tag (well, you could do it, but it would apply to your search results too).
So after all that, I’d say what you have is the best fit for your desired result. Someone with a better grasp of the tags may have a different take on it of course ;-)
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
#7 2009-10-23 12:48:21
- timstr
- New Member
- Registered: 2006-12-14
- Posts: 6
Re: Disabling search_results?
Solved.
MattD, Gocom, Bloke; thanks for your input!
Offline
Pages: 1