Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
[solved] Search URL detection
I have two search URLs:
http://txp-bp.localhost/?q=woo
http://txp-bp.localhost/?q=pop
I’m using if_search
to figure out what pages are content and style accordingly. The two URLs above behave differently with my if_search
code and I don’t know why.
Here’s my page code:
<txp:if_status status="200">
<txp:if_article_list>
<txp:if_section name="default">
<txp:if_search>
<p>is search (page)</p>
<txp:article searchform="default" />
<txp:else />
<txp:if_category>
<p>is category (page)</p>
<txp:else />
<p>is homepage (page)</p>
</txp:if_category>
</txp:if_search>
<txp:else />
<p>is section (page)</p>
</txp:if_section>
<txp:else />
<p>is article (page)</p>
</txp:if_article_list>
<txp:else />
<txp:if_status status="401">
<p>is 401 (page)</p>
</txp:if_status>
<txp:if_status status="403">
<p>is 403 (page)</p>
</txp:if_status>
<txp:if_status status="404">
<p>is 404 (page)</p>
</txp:if_status>
<txp:if_status status="410">
<p>is 410 (page)</p>
</txp:if_status>
<txp:if_status status="500">
<p>is 500 (page)</p>
</txp:if_status>
<txp:if_status status="503">
<p>is 503 (page)</p>
</txp:if_status>
</txp:if_status>
My code is intended to output ‘is search (page)’ as a marker to me so I know I’m looking at a search page in the browser and the (page) bit tells me the marker came from the default Textpattern page. As search results need an article tag, I’m using default
with this code:
<txp:if_status status="200">
<txp:if_article_list>
<txp:if_section name="default">
<txp:if_search>
<p>is search (form)</p>
<txp:else />
<txp:if_category>
<p>is category (form)</p>
<txp:else />
<txp:if_author>
<p>is author (form)</p>
<txp:else />
<p>is homepage (form)</p>
</txp:if_author>
</txp:if_category>
</txp:if_search>
<txp:else />
<p>is article list, not default (form)</p>
</txp:if_section>
<txp:else />
<txp:if_status status="200">
<p>is individual article (form)</p>
</txp:if_status>
</txp:if_article_list>
<txp:else />
<txp:if_status status="401">
<p>401 error text (form)</p>
</txp:if_status>
<txp:if_status status="403">
<p>403 error text (form)</p>
</txp:if_status>
<txp:if_status status="404">
<p>404 error text (form)</p>
</txp:if_status>
<txp:if_status status="410">
<p>410 error text (form)</p>
</txp:if_status>
<txp:if_status status="500">
<p>500 error text (form)</p>
</txp:if_status>
<txp:if_status status="503">
<p>503 error text (form)</p>
</txp:if_status>
</txp:if_status>
Note there are no if_search_results
conditions in either code block. What I expect to see for a search page, therefore, is this:
is search (page)
is search (form)
…indicating that the default
page has detected search, and then a new paragraph to tell me the the default
form has done the same, albeit with different words.
For this URL:
http://txp-bp.localhost/?q=woo
I see this:
is search (page)
is search (form)
Which is great. However, this URL:
http://txp-bp.localhost/?q=pop
…gives me this output:
is search (page)
So, no search detection from the form side of things. I am confused. What did I do wrong?
There is one test article which contains the string ‘woo’ in the body, but not ‘pop’. In both instances, leaving out the article searchform="default"
tag in debug mode triggers the ‘you need an article tag’ warning, and yet having the article tag in play doesn’t provide any output in the ‘pop’ instance.
Any advice appreciated, sirs and misses. Thank you.
Offline
Re: [solved] Search URL detection
woo tag trace
<!-- txp tag trace:
[SQL (0.0031509399414062): select name, data from txp_lang where lang='en-gb' AND ( event='public' OR event='common')]
[SQL (0.00040602684020996): select name, code, version from txp_plugin where status = 1 AND type IN (0,1,5) order by load_order]
[SQL (0.00031089782714844): select page, css from txp_section where name = 'default' limit 1]
[SQL (0.00040793418884277): select host from txp_log where ip='127.0.0.1' limit 1]
[SQL (0.00055193901062012): insert into txp_log set `time`=now(),page='/?q=woo',ip='127.0.0.1',host='localhost',refer='',status='200',method='GET']
[SQL (0.00041389465332031): select user_html from txp_page where name='default']
[Page: default]
<txp:rah_replace from=" ,
" to="">
<txp:hide>
</txp:hide>
<txp:variable name="disqus_status" value="0" />
<txp:if_variable name="disqus_status" value="1">
[<txp:if_variable name="disqus_status" value="1">: false]
</txp:if_variable>
<txp:variable name="google_analytics_status" value="0" />
<txp:if_variable name="google_analytics_status" value="1">
[<txp:if_variable name="google_analytics_status" value="1">: false]
</txp:if_variable>
<txp:variable name="google_plus_status" value="0" />
<txp:if_variable name="google_plus_status" value="1">
[<txp:if_variable name="google_plus_status" value="1">: false]
</txp:if_variable>
<txp:variable name="google_tag_manager_status" value="0" />
<txp:if_variable name="google_tag_manager_status" value="1">
[<txp:if_variable name="google_tag_manager_status" value="1">: false]
</txp:if_variable>
<txp:variable name="hittail_status" value="0" />
<txp:if_variable name="hittail_status" value="1">
[<txp:if_variable name="hittail_status" value="1">: false]
</txp:if_variable>
<txp:variable name="jplayer_status" value="0" />
<txp:variable name="opengraph_status" value="0" />
<txp:variable name="schema_status" value="0" />
<txp:variable name="twitter_cards_status" value="0" />
<txp:if_status status="200">
[<txp:if_status status="200">: true]
<txp:if_article_list>
[<txp:if_article_list>: true]
<txp:if_section name="default">
[<txp:if_section name="default">: true]
<txp:if_search>
[<txp:if_search>: true]
<txp:search_term />
</txp:if_search>
</txp:if_section>
</txp:if_article_list>
</txp:if_status>
<txp:site_name />
<txp:if_variable name="jplayer_status" value="1">
[<txp:if_variable name="jplayer_status" value="1">: false]
</txp:if_variable>
<txp:if_article_list>
[<txp:if_article_list>: true]
<txp:if_section name="default">
[<txp:if_section name="default">: true]
<txp:if_search>
[<txp:if_search>: true]
<txp:site_url />
<txp:page_url type='q' />
</txp:if_search>
</txp:if_section>
</txp:if_article_list>
<txp:feed_link flavor="atom" format="link" label="Atom" />
<txp:feed_link flavor="rss" format="link" label="RSS" />
<txp:if_individual_article>
[<txp:if_individual_article>: false]
</txp:if_individual_article>
<txp:if_variable name="google_plus_status" value="0">
[<txp:if_variable name="google_plus_status" value="0">: true]
</txp:if_variable>
<txp:if_status status="200">
[<txp:if_status status="200">: true]
<txp:if_article_list>
[<txp:if_article_list>: true]
<txp:if_section name="default">
[<txp:if_section name="default">: true]
<txp:if_search>
[<txp:if_search>: true]
<txp:search_term />
<txp:site_name />
</txp:if_search>
</txp:if_section>
</txp:if_article_list>
</txp:if_status>
<txp:if_variable name="google_tag_manager_status" value="1">
[<txp:if_variable name="google_tag_manager_status" value="1">: false]
</txp:if_variable>
<txp:if_status status="200">
[<txp:if_status status="200">: true]
<txp:if_article_list>
[<txp:if_article_list>: true]
<txp:if_section name="default">
[<txp:if_section name="default">: true]
<txp:if_search>
[<txp:if_search>: true]
<txp:article searchform="default" />
[filterAtts accepted]
[SQL (0.00042200088500977): select name from txp_section where searchable != '1']
[SQL (0.00029516220092773): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (`Title` like '%woo%' or `Body` like '%woo%') ]
[SQL (0.00041389465332031): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod, match (`Title`, `Body`) against ('woo') as score from textpattern where 1=1 and Status = 4 and Posted <= now() and (`Title` like '%woo%' or `Body` like '%woo%') order by score desc limit 0, 10]
[Article 2]
[SQL (0.00018811225891113): select Form from txp_form where name='default']
[Form: default]
<txp:rah_replace from=" ,
" to="">
<txp:hide>
</txp:hide>
<txp:if_status status="200">
[<txp:if_status status="200">: true]
<txp:if_article_list>
[<txp:if_article_list>: true]
<txp:if_section name="default">
[<txp:if_section name="default">: true]
<txp:if_search>
[<txp:if_search>: true]
</txp:if_search>
</txp:if_section>
</txp:if_article_list>
</txp:if_status>
<txp:hide>
</txp:hide>
</txp:rah_replace>
</txp:if_search>
</txp:if_section>
</txp:if_article_list>
</txp:if_status>
<txp:if_variable name="google_analytics_status" value="1">
[<txp:if_variable name="google_analytics_status" value="1">: false]
</txp:if_variable>
<txp:if_variable name="hittail_status" value="1">
[<txp:if_variable name="hittail_status" value="1">: false]
</txp:if_variable>
<txp:hide>
</txp:hide>
</txp:rah_replace>
[ ~~~ secondpass ~~~ ]
-->
Last edited by gaekwad (2013-12-02 16:22:13)
Offline
Re: [solved] Search URL detection
pop tag trace
<!-- txp tag trace:
[SQL (0.0052058696746826): select name, data from txp_lang where lang='en-gb' AND ( event='public' OR event='common')]
[SQL (0.00040102005004883): select name, code, version from txp_plugin where status = 1 AND type IN (0,1,5) order by load_order]
[SQL (0.0003809928894043): select page, css from txp_section where name = 'default' limit 1]
[SQL (0.00048589706420898): select host from txp_log where ip='127.0.0.1' limit 1]
[SQL (0.00040984153747559): insert into txp_log set `time`=now(),page='/?q=pop',ip='127.0.0.1',host='localhost',refer='',status='200',method='GET']
[SQL (0.00030303001403809): select user_html from txp_page where name='default']
[Page: default]
<txp:rah_replace from=" ,
" to="">
<txp:hide>
</txp:hide>
<txp:variable name="disqus_status" value="0" />
<txp:if_variable name="disqus_status" value="1">
[<txp:if_variable name="disqus_status" value="1">: false]
</txp:if_variable>
<txp:variable name="google_analytics_status" value="0" />
<txp:if_variable name="google_analytics_status" value="1">
[<txp:if_variable name="google_analytics_status" value="1">: false]
</txp:if_variable>
<txp:variable name="google_plus_status" value="0" />
<txp:if_variable name="google_plus_status" value="1">
[<txp:if_variable name="google_plus_status" value="1">: false]
</txp:if_variable>
<txp:variable name="google_tag_manager_status" value="0" />
<txp:if_variable name="google_tag_manager_status" value="1">
[<txp:if_variable name="google_tag_manager_status" value="1">: false]
</txp:if_variable>
<txp:variable name="hittail_status" value="0" />
<txp:if_variable name="hittail_status" value="1">
[<txp:if_variable name="hittail_status" value="1">: false]
</txp:if_variable>
<txp:variable name="jplayer_status" value="0" />
<txp:variable name="opengraph_status" value="0" />
<txp:variable name="schema_status" value="0" />
<txp:variable name="twitter_cards_status" value="0" />
<txp:if_status status="200">
[<txp:if_status status="200">: true]
<txp:if_article_list>
[<txp:if_article_list>: true]
<txp:if_section name="default">
[<txp:if_section name="default">: true]
<txp:if_search>
[<txp:if_search>: true]
<txp:search_term />
</txp:if_search>
</txp:if_section>
</txp:if_article_list>
</txp:if_status>
<txp:site_name />
<txp:if_variable name="jplayer_status" value="1">
[<txp:if_variable name="jplayer_status" value="1">: false]
</txp:if_variable>
<txp:if_article_list>
[<txp:if_article_list>: true]
<txp:if_section name="default">
[<txp:if_section name="default">: true]
<txp:if_search>
[<txp:if_search>: true]
<txp:site_url />
<txp:page_url type='q' />
</txp:if_search>
</txp:if_section>
</txp:if_article_list>
<txp:feed_link flavor="atom" format="link" label="Atom" />
<txp:feed_link flavor="rss" format="link" label="RSS" />
<txp:if_individual_article>
[<txp:if_individual_article>: false]
</txp:if_individual_article>
<txp:if_variable name="google_plus_status" value="0">
[<txp:if_variable name="google_plus_status" value="0">: true]
</txp:if_variable>
<txp:if_status status="200">
[<txp:if_status status="200">: true]
<txp:if_article_list>
[<txp:if_article_list>: true]
<txp:if_section name="default">
[<txp:if_section name="default">: true]
<txp:if_search>
[<txp:if_search>: true]
<txp:search_term />
<txp:site_name />
</txp:if_search>
</txp:if_section>
</txp:if_article_list>
</txp:if_status>
<txp:if_variable name="google_tag_manager_status" value="1">
[<txp:if_variable name="google_tag_manager_status" value="1">: false]
</txp:if_variable>
<txp:if_status status="200">
[<txp:if_status status="200">: true]
<txp:if_article_list>
[<txp:if_article_list>: true]
<txp:if_section name="default">
[<txp:if_section name="default">: true]
<txp:if_search>
[<txp:if_search>: true]
<txp:article searchform="default" />
[filterAtts accepted]
[SQL (0.00041103363037109): select name from txp_section where searchable != '1']
[SQL (0.00025701522827148): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (`Title` like '%pop%' or `Body` like '%pop%') ]
[SQL (0.00033688545227051): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod, match (`Title`, `Body`) against ('pop') as score from textpattern where 1=1 and Status = 4 and Posted <= now() and (`Title` like '%pop%' or `Body` like '%pop%') order by score desc limit 0, 10]
</txp:if_search>
</txp:if_section>
</txp:if_article_list>
</txp:if_status>
<txp:if_variable name="google_analytics_status" value="1">
[<txp:if_variable name="google_analytics_status" value="1">: false]
</txp:if_variable>
<txp:if_variable name="hittail_status" value="1">
[<txp:if_variable name="hittail_status" value="1">: false]
</txp:if_variable>
<txp:hide>
</txp:hide>
</txp:rah_replace>
[ ~~~ secondpass ~~~ ]
-->
Last edited by gaekwad (2013-12-02 16:22:34)
Offline
Re: [solved] Search URL detection
gaekwad wrote:
I’m using if_search to figure out what pages are content and style accordingly. The two URLs above behave differently with my
if_search
code and I don’t know why.
Both behave the same. Parser end up to the same place, difference is that there is no search results for the latter, while the there is one result for the first. If there is no results, the form isn’t going to be used either.
That said, I wouldn’t put those conditions to article, file or link forms. Do your conditions outside the forms and list loops where possible to save server resources. And, I would remove all those status checks. They don’t do anything in normal forms and templates; a normal template is never going to be used on error. All errors use different templates.
Offline
Re: [solved] Search URL detection
Jukka, thank you for your reply.
Gocom wrote:
Both behave the same. Parser end up to the same place, difference is that there is no search results for the latter, while the there is one result for the first. If there is no results, the form isn’t going to be used either.
Should I perhaps update the if_search
documentation, then? My understanding, which was what led to this confusion, I think, was that the if_search
tag was a conditional to check if what was being displayed is the result of a search which, strictly speaking, they both are. The number of results is not relevant; both pages are search pages.
That said, I wouldn’t put those conditions to article, file or link forms.
I should have expanded on my footer on the original post: I’m debugging and moving things around to see what works for best for me. There were, and are, duplicates that will be resolved. I’m still putting the groundwork together for a new site and I’m paring it back once I know what is ‘best’. I’ll take your advice on rehoming outside of forms.
Offline
Re: [solved] Search URL detection
gaekwad wrote:
Should I perhaps update the
if_search
documentation, then? My understanding, which was what led to this confusion, I think, was that theif_search
tag was a conditional to check if what was being displayed is the result of a search which, strictly speaking, they both are. The number of results is not relevant; both pages are search pages.
This is not to do with the if_search tag; in both cases the tag evaluates true. Its the article tag that isn’t returning any results as there are no matching articles.
Offline
Re: [solved] Search URL detection
Gocom wrote:
Its the article tag that isn’t returning any results as there are no matching articles.
I undertand (I think). My literal interpretation was a bit too literal. Thank you very much for your clarification, I am grateful.
Offline
Pages: 1