Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-11-05 10:06:22

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,659
GitHub Twitter

Seach results and empty excerpts

Hi, TXP folks :)

Due to a visual organisation of search results in order to distinguish the articles titles vs the search excerpts, if only a title matches a search term no excerpt is displayed and my (attempted) structure is broken.

So I do that:

<txp:php>
$some = search_result_excerpt(array());
echo( ($some ? $some : '(&hellip;)') );
</txp:php>

Is there better solutions?

Last edited by Pat64 (2013-11-05 10:10:20)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#2 2013-11-05 13:53:02

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: Seach results and empty excerpts

Here’s a possible native way but I think that your way should be lighter to the system:)

<txp:if_search_results>
<txp:variable name="onlyone" value='<txp:search_result_count />' />
<txp:if_variable name="onlyone" value="1">
do what you want
<txp:else />
more results
</txp:if_variable>
</txp:if_search_results>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2013-11-05 18:46:31

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,659
GitHub Twitter

Re: Seach results and empty excerpts

Hey Yiannis, that’s a very good exemple of a result with only native tags!

Don’t know if a new <txp:if_search_result_excerpt> tag will be useful for everyone?

Thanks lot for your reply.

Cheers,

Last edited by Pat64 (2013-11-05 18:48:00)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#4 2013-11-06 06:15:21

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: Seach results and empty excerpts

Hi Pat,

I reread your original post and realised that I misread it first time. Here’s the correct code.

<txp:if_search_results>
<txp:variable name="hasexcerpt" value='<txp:search_result_excerpt />' />
<txp:if_variable name="hasexcerpt" value="">
do what you want
<txp:else />
more results
</txp:if_variable>
<txp:else />
No results
</txp:if_search_results>

Re the <txp:if_search_result_excerpt>, it can be achieved with variables but I can understand its possible usefulness as search could also be used for keywords/custom_fields etc in certain installs and – using variables is not friendly for beginners.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2013-11-06 06:36:20

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,659
GitHub Twitter

Re: Seach results and empty excerpts

:)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

Board footer

Powered by FluxBB