Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: etc_search: when the default search is not enough
etc wrote #293224:
<txp:article_custom exclude='<txp:article_id />'...
I like that at a lot. Just yesterday I was looking to grab all articles except those in a certain category… Could something like that work here without doing an article_custom as a tag in tag? In the end I went with an if_article_category construction in the article_custom’s output which works but is sub-optimal.
TXP Builders – finely-crafted code, design and txp
Offline
Re: etc_search: when the default search is not enough
etc wrote #293224:
If it stays there
No plans to remove it. A great contribution, thank you. Very handy indeed.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: etc_search: when the default search is not enough
jakob wrote #293273:
I was looking to grab all articles except those in a certain category… Could something like that work here without doing an article_custom as a tag in tag?
No, I’m afraid, the current way would be
<txp:article_custom exclude='<txp:article_custom category="certain-category" break=","><txp:article_id /></txp:article_custom>' />
which is not optimal too, but cleaner and will respect the eventual limit attribute.
It is not difficult to extend exclude to something like ID : 1,2,3 | category : certain-category | ..., but it looks bloated. More general possibility is to instruct the parser to recognize “is different” patterns, say att!="value", and let each tag to decide what it does with it. But it’s mucho tags code rewrite, if we want to be coherent.
Offline
#79 2015-07-16 12:06:23
- makss
- Plugin Author
- From: Ukraine
- Registered: 2008-10-21
- Posts: 355
Re: etc_search: when the default search is not enough
jakob wrote #293273:
<txp:article_custom exclude='<txp:article_id />'...
I like that at a lot. Just yesterday I was looking to grab all articles except those in a certain category… Could something like that work here without doing an article_custom as a tag in tag?
You can use the plugin aks_article , which supports SQL syntax where=
<txp:aks_article where="category1<>'certain-category' and category2<>'certain-category'"/>
You can specify additional attribute hideself="1" – Are excluded from the list of current article.
aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)
Offline
Re: etc_search: when the default search is not enough
Hey, but you can use etc_search too, while we are here. :)
Offline
#81 2016-02-28 09:27:50
- lazlo
- Member
- Registered: 2004-02-24
- Posts: 110
Re: etc_search: when the default search is not enough
Hey Oleg (or others)
Is there a simple way to hide a search result that has no return?
“Sorry, no results found matching your search request”
EDIT: The answer for above question from Oleg is added here.
ANSWER:
<txp:etc_search_results id="8" form="book_title_only" limit="1" query='<txp:article_url_title />'>
<txp:else />
<!-- no match -->
</txp:etc_search_results>
Also maybe not so simple:
I have a Tab that is called “News” the code searches for related News using etc_search.
I would like to hide the tab as well.
<div class="tab-v1">
<ul class="nav nav-tabs">
<li class="active"><a href="#profiles" data-toggle="tab">Contributor Profiles</a></li>
<txp:hide><li><a href="#reviews" data-toggle="tab">Reviews</a></li></txp:hide>
<li><a href="#news" data-toggle="tab">Recent News</a></li>
<li><a href="#events" data-toggle="tab">Upcoming Events</a></li>
</ul><!--=== End Tab Headers ===-->
further down is
<div class="class="col-md-12""><!--=== Interior Content ===-->
<txp:etc_search_results id="4" query='<txp:title/>' form="newslistExcerpt" />
</div><!--=== End Interior Content ===-->
Last edited by lazlo (2016-04-22 18:48:02)
Offline
Re: etc_search: when the default search is not enough
lazlo wrote #298046:
Hey Oleg (or others)
Is there a simple way to hide a search result that has no return?
“Sorry, no results found matching your search request”
Hi Leslie,
if you mean the output of <txp:etc_search_results />, try to wrap it (and surrounding tags, if necessary) in <txp:if_search_results></txp:if_search_results>. For live search this is trickier, though.
Edit: Try rather this:
<txp:variable name="search_results" value='<txp:etc_search_results />' />
<txp:if_search_results>
... surrounding code ...
<txp:variable name="search_results" >/
... surrounding code ...
</txp:if_search_results>
Last edited by etc (2016-02-28 20:17:38)
Offline
#83 2016-04-21 20:30:58
- lazlo
- Member
- Registered: 2004-02-24
- Posts: 110
Re: etc_search: when the default search is not enough
etc wrote #298052:
if you mean the output of
<txp:etc_search_results />, try to wrap it (and surrounding tags, if necessary) in<txp:if_search_results></txp:if_search_results>. For live search this is trickier, though.Edit: Try rather this:
I tried that code exactly I couldn’t get a result. I am not sure <txp:etc_search_results /> plays well with <txp:if_search_results>
I tried a version without the variable and couldn’t get <txp:if_search_results> to trigger but I could get <txp:if_search> to trigger.
<txp:etc_search_results />
<txp:if_search>
DISPLAYS TEXT
</txp:if_search>
but
<txp:etc_search_results />
<txp:if_search_results>
DISPLAYS NO TEXT
</txp:if_search_results>
They both should display text if there are search results but only <txp:if_search> does.
Offline
Re: etc_search: when the default search is not enough
Sorry Les, can not reproduce. Are you sure the concerned <txp:etc_search_results /> is not preceded by <txp:article /> or other <txp:etc_search_results /> in this part?
Offline
#85 2016-04-21 22:02:21
- lazlo
- Member
- Registered: 2004-02-24
- Posts: 110
Re: etc_search: when the default search is not enough
My exact code for the nested form that doesn’t display the results
<!--=== Checking to see If Book Cover Image Exists ===-->
<txp:adi_if_content>
<div class="col-md-4 col-sm-4 col-xs-9">
<div class="product-img product-img-brd">
<txp:permlink><txp:article_image class="full-width img-responsive" escape="" /></txp:permlink>
<!--=== If Book Cover Image Exists Do This ===-->
<txp:adi_if_content_insert>
<!--=== This Code Displays Nothing ===-->
<txp:variable name="search_results" value='<txp:etc_search_results id="8" form="book_title_only" limit="1" query=''<txp:article_url_title />'' />' />
<txp:if_search_results>
<txp:variable name="search_results" />
</txp:if_search_results>
</txp:adi_if_content_insert>
</div>
</div>
</txp:adi_if_content>
Change to <txp:if_search> and the search results are displayed.
<!--=== Checking to see If Book Cover Image Exists ===-->
<txp:adi_if_content>
<div class="col-md-4 col-sm-4 col-xs-9">
<div class="product-img product-img-brd">
<txp:permlink><txp:article_image class="full-width img-responsive" escape="" /></txp:permlink>
<!--=== If Book Cover Image Exists Do This ===-->
<txp:adi_if_content_insert>
<!--=== This Code Displays The Search Results ===-->
<txp:variable name="search_results" value='<txp:etc_search_results id="8" form="book_title_only" limit="1" query=''<txp:article_url_title />'' />' />
<txp:if_search>
<txp:variable name="search_results" />
</txp:if_search>
</txp:adi_if_content_insert>
</div>
</div>
</txp:adi_if_content>
Could the code calling this form be causing the problem or the <txp:article_image /> tag?
Offline
Re: etc_search: when the default search is not enough
Ah, if you use it in an article form, this will not work, because if_search_results is set only once, by the first etc_search_results call or even before, by some other tag. Try
<txp:variable name="search_results" value='<txp:etc_search_results id="8" form="book_title_only" limit="1" query=''<txp:article_url_title />'' />' />
<txp:if_variable name="search_results" value='<txp:text item="no_search_matches" />'>
<!-- no match -->
<txp:else />
<txp:variable name="search_results" />
</txp:if_variable>
But actually you should be able to replace this block with (less ugly)
<txp:etc_search_results id="8" form="book_title_only" limit="1" query='<txp:article_url_title />'>
<txp:else />
<!-- no match -->
</txp:etc_search_results>
Offline
#87 2016-04-22 18:43:35
- lazlo
- Member
- Registered: 2004-02-24
- Posts: 110
Re: etc_search: when the default search is not enough
etc wrote #298767:
But actually you should be able to replace this block with (less ugly)
<txp:etc_search_results id="8" form="book_title_only" limit="1" query='<txp:article_url_title />'>...
HUZZAH! That works perfectly, and expands my knowledge of <txp:else /> without an actual <txp:if.../>.
Offline
Re: etc_search: when the default search is not enough
An attribute could probably be handier than <txp:else />. How would you call it: no_results? no_matches?
Offline
#89 2016-04-25 01:14:55
- lazlo
- Member
- Registered: 2004-02-24
- Posts: 110
Re: etc_search: when the default search is not enough
no_matches works for me.
Offline
Offline