Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[Solved] Extraction for all articles containing a unique title string
Hi, TXP Experts: magicians of tags! You, Harry Potter of the code.
It is possible to extract all articles containing a unique title occurrence based on a comma separated list stored into a TXP variable?
Here is how the variable is set: element 1,element 2, element 3
Here is how the article titles are set:
My title element 1, My other title element 1, My title element 2, My title element 3, My other title element 2
Last edited by Pat64 (2021-12-06 06:41:37)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Extraction for all articles containing a unique title string
would this be of help?
<txp:article_custom section="your_section" break="li" wraptag="ul">
<txp:variable name="title_filter"><txp:title /></txp:variable>
<txp:if_variable name="title_filter" value="element">
<txp:permlink><txp:title /></txp:permlink>
</txp:if_variable>
</txp:article_custom>
Alternatively this may also work:
<txp:article_custom section="your_section" title="element" break="li" wraptag="ul">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [Solved] Extraction for all articles containing a unique title string
Iterating isn’t very well implemented at the moment without a plugin (e.g. rah_repeat).
Selecting via title
in <txp:article_custom>
isn’t supported as far as I recall (though url_title might… can’t remember if Oleg added it.)
Beyond messing with trim
and replace
you’re really only left with what Yiannis suggests: iterate over the articles and check if the article title is in the list in your variable:
<txp:article_custom section="your_section" limit="999">
<if::variable name="cs_list" separator="," value='<txp:title trim />' match="any">
<txp:title /> MATCHES
</if::variable>
</txp:article_custom>
Slow and processor intensive, so not recommended for long lists.
EDIT: and if the variable doesn’t exactly match the title, as you suggest in the OP, then you can fall back on the pattern
attribute perhaps?
Last edited by Bloke (2021-12-01 12:54:25)
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
Re: [Solved] Extraction for all articles containing a unique title string
Bloke wrote #332070:
Iterating isn’t very well implemented at the moment without a plugin (e.g. rah_repeat).
Selecting via
title
in<txp:article_custom>
isn’t supported as far as I recall (though url_title might… can’t remember if Oleg added it.)
I suggested it there as I took it that all fields in the write page are by default custom_fields. There is already support for <txp:article_custom colour="red" />
so title
may work.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [Solved] Extraction for all articles containing a unique title string
colak wrote #332072:
I suggested it there as I took it that all fields in the write page are by default custom_fields. There is already support for
<txp:article_custom colour="red" />
sotitle
may work.
Ah yeah, sadly that fact/hack is only exposed in the custom_fields tags. In the article tags, the custom field matching is restricted to actual CFs (as far as I know, though I must admit I’ve never tried it) or the dedicated attributes we expose.
Be interesting to see if it did work, though I suspect not.
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
Re: [Solved] Extraction for all articles containing a unique title string
Thanks lot, magicians!
I think I’m going to find a solution (I will give you my process, later, if it’s efficient). But I need and advice:
How can you sort <txp:article_custom />
by… <txp:variable />
?
Trying that without any results:
sort="<txp:variable name='cs_list' />, asc"
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
#7 2021-12-01 18:57:47
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,304
Re: [Solved] Extraction for all articles containing a unique title string
Pat64 wrote #332074:
sort="<txp:variable name='cs_list' />, asc"...
Hi Patrick!
Is that verbatim, i.e. copied/pasted? Or have you tried single quotes like that:
sort='<txp:variable name="cs_list" />, asc'...
Edit: typo.
Last edited by uli (2021-12-01 18:58:55)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: [Solved] Extraction for all articles containing a unique title string
uli wrote #332075:
Hi Patrick!
Is that verbatim, i.e. copied/pasted? Or have you tried single quotes like that:
sort='<txp:variable name="cs_list" />, asc'...
Nope. I tried but with error message…
As Bloke said, iteration is difficult. So the only solution is to use a MySQL query.
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Extraction for all articles containing a unique title string
Bloke wrote #332070:
Iterating isn’t very well implemented at the moment without a plugin (e.g. rah_repeat).
It is powerful enough in 4.8.8, see below.
Selecting via
title
in<txp:article_custom>
isn’t supported as far as I recall (though url_title might… can’t remember if Oleg added it.)
A possible option is setting searchable fields to Title
in wet_haystack, but this is not very practical, I guess.
One can filter by url_title
, though, but you need to pass by $_GET
array to filter by multiple values. To simplify, store search strings as LIKE
patterns:
<txp:variable name="cs_list" value="%element_1%, %element_2%, ..." />
<txp:php>
$_GET['title'] = do_list(processTags('variable', array('name' => 'cs_list')));
</txp:php>
<txp:article_custom match="url_title=title" />
For you sort
problem, try (4.8.8)
sort='FIELD(Title, <txp:variable name="title_list" escape="db, quote" break="," />)'
But the entries of title_list
must match titles exactly.
Offline
Re: [Solved] Extraction for all articles containing a unique title string
@Oleg:
Thank you lot Sir for your help! Give me some time to try. I’ll come back here later. ;)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Extraction for all articles containing a unique title string
I’ve gotten around this in the past by including the sort value and direction in the same variable:
<txp:variable name='cs_list' value="custom_1 asc"/>
sort='<txp:variable name='cs_list' />'...
Offline
Re: [Solved] Extraction for all articles containing a unique title string
giz wrote #332079:
I’ve gotten around this in the past by including the sort value and direction in the same variable:
<txp:variable name='cs_list' value="custom_1 asc"/>...
Interesting! Tks ;)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline