Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-01-16 08:54:20

fm
New Member
From: Hannover, Germany
Registered: 2004-10-08
Posts: 3

... display a message whether search result returns no match found

I’d like do have a search result message like “Sorry, no match found for your request”, whether the request returns no hits.
Is there a special search tag like [b]txp:if_no_search_results[/b] in textpattern?

Thanks for your help

fm

Last edited by fm (2006-01-16 08:55:05)

Offline

#2 2006-01-16 11:24:03

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,352
Website GitHub Mastodon

Re: ... display a message whether search result returns no match found

If PHP is enabled in your page template, you could add the sequence below to your page template:

<txp:php>
global $thispage; global $q;
echo( ($thispage['total']==0 ? 
"Sorry, no match found for your request." : 
"Your search for <strong>$q</strong> resulted in ".$thispage['total']." hits." ) );
</txp:php>

which will return either “Sorry, no match found for your request.” or “Your search result for search-term resulted in count hits.”

Last edited by wet (2006-02-20 16:41:23)

Offline

#3 2006-01-16 21:39:47

fm
New Member
From: Hannover, Germany
Registered: 2004-10-08
Posts: 3

Re: ... display a message whether search result returns no match found

Hi wet,

thanks for your support. Works great.

fm

Offline

#4 2006-02-20 07:06:34

Luxebot
Member
From: Los Angeles
Registered: 2006-02-18
Posts: 25

Re: ... display a message whether search result returns no match found

Thank you for the help! Unfortunately, I get a parse error — this is exactly what it says:

[code]Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/flint3/public_html/site/textpattern/publish/taghandlers.php(1726) : eval()’d code on line 2[/code]

This is what I have in my page template:

[code]<txp:if_search><txp:php>
global$thispage;global$q;echo(($thispage[‘total’]==0?Sorry, no match found for your request.“Your search for <strong>$q</strong> resulted in $thispage[‘total’]hits.”));
</txp:php></txp:if_search>[/code]

I have a search form on every page. If you’d like to check it out, it’s at http://flintcanyontennisclub.com/site

Thank you so much :)

*** Edit ***

Umm, for some reason the special code box isn’t showing up for me, and there is no option to attach a .txt file so I can communicate what exactly is going on. How do you do that?

Last edited by Luxebot (2006-02-20 07:15:37)

Offline

#5 2006-02-20 07:15:12

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,352
Website GitHub Mastodon

Re: ... display a message whether search result returns no match found

> Luxebot wrote:

<txp:if_search><txp:php>
global$thispage;global$q;
echo(($thispage['total']==0?"Sorry, no match found for your request.":"Your search for <strong>$q</strong> resulted in $thispage['total']hits."));
</txp:php></txp:if_search>

The blanks after both global modifiers are missing, but relevant. It should read global $thispage;global $q;.

Offline

#6 2006-02-20 07:21:08

Luxebot
Member
From: Los Angeles
Registered: 2006-02-18
Posts: 25

Re: ... display a message whether search result returns no match found

Hmm, ok, now it says:

[code]Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or ‘{’ or ‘$’ in /home/flint3/public_html/site/textpattern/publish/taghandlers.php(1726) : eval()’d code on line 2[/code]

I am putting the < txp:ifsearch > tags around the whole thing too …

Last edited by Luxebot (2006-02-20 07:27:28)

Offline

#7 2006-02-20 07:29:44

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,352
Website GitHub Mastodon

Re: ... display a message whether search result returns no match found

How to post code here: Precede you code block with bc.. , precede subsequent normal paragraphs with p. . Or post code over there and link to your snippets from here. This forum uses Textile for markup.

Offline

#8 2006-02-20 07:44:57

Luxebot
Member
From: Los Angeles
Registered: 2006-02-18
Posts: 25

Re: ... display a message whether search result returns no match found

Ok, thanks!

However, I’m still getting errors — I’m not much of a php coder, from what you can see. This is what I get now:

bc..Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/flint3/public_html/site/textpattern/publish/taghandlers.php(1726) : eval()’d code on line 6

Last edited by Luxebot (2006-02-20 07:45:28)

Offline

#9 2006-02-20 15:57:33

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: ... display a message whether search result returns no match found

similar problems here.

bc..

Parse error: syntax error, unexpected
T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or
T_VARIABLE or T_NUM_STRING in

although maybe support for 0-results searches should be better integrated into TXP, and this is should be a feature request?


Yes, I have tried turning it off and on.

Offline

#10 2006-02-20 16:46:11

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,352
Website GitHub Mastodon

Re: ... display a message whether search result returns no match found

Ah, I see. Please amend the next-to-last line as such:

"Your search for <strong>$q</strong> resulted in ".$thispage['total']." hits." ) );

Mind the dots. I have also corrected the snippet in the original post above.

Offline

#11 2006-02-20 18:33:17

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: ... display a message whether search result returns no match found

now I get “Sorry, no match found for your request.” every time, even on a page that’s NOT a search-results page. “I don’t see the “Your search for . . .” part anytime, on valid or invalid search.


Yes, I have tried turning it off and on.

Offline

#12 2006-02-20 18:35:29

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,352
Website GitHub Mastodon

Re: ... display a message whether search result returns no match found

txp:if_search is used to conditionally include parts of the page template when a search result listing is displayed.

Last edited by wet (2006-02-20 18:37:41)

Offline

Board footer

Powered by FluxBB