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.
Hire 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
titlein<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" />sotitlemay 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.
Hire 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,319
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
titlein<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
Re: [Solved] Extraction for all articles containing a unique title string
Hey Txp lovers!
Solved by… Textpattern: this amazing CMS! 😜
I will explain today my problem’s solution; give me some hours because I’m tired…
Here is the results where this page display, by unique author, all their corresponding books. The main page have, above the footer, an unordered list of unique authors name (despite the number of individual books) each associated by an anchor to the second page. 👌
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
Lovely site Patrick! Nice books too. Like Yiannis mentioned elsewhere, I wish my French was better than it is. I’m taking lessons so perhaps someday …
I’d love to see your solution when you have time. And I’d also like to hear more about your cart solution :-)
TXP Builders – finely-crafted code, design and txp
Offline
Re: [Solved] Extraction for all articles containing a unique title string
To keep all simplest for the client, all article titles use an “at” sign (@) chosen as a very improbable book title occurrence. These titles are formatted as our needs with some Regex (thank you lot Julian for your help ;).
Title of the book@ Author Name
My problem consisted of book author’s names extraction by unique occurrences (shown within the footer part of the website):
<ul class="_inner cf mb4em no-list">
<txp:article_custom section="my-section" exclude="4" sort="FIELD(ID, '<txp:title />'), SUBSTRING_INDEX(Title, '@', -1) asc" limit="0" time="any" trim='/(.*\s@)/' replace><txp:variable name="anchor" trim><txp:title trim='/(.*@\s)(.*)/' replace='$2' /></txp:variable>
<li class="fl-l mb2em"><a rel="tag" href="<txp:site_url />ecrivains/#a-<txp:php>global $variable;$str = str_replace(array(' ', ''', 'E', 'É', 'é'), array('-', '-', 'e', 'e', 'e'), $variable['anchor']);$str = iconv("utf-8", "ascii//TRANSLIT",$str); echo strtolower($str);</txp:php>" class="btn trans round"><h4><i class="icon" aria-hidden="true">#</i> <txp:title trim='/(.*\@)(.*)/' replace='$2' /></h4></a></li>
</txp:article_custom>
</ul>
Note: for anchor links I couldn’t find any other way (all French characters converted to lowercase; all spaces changed by dashes)…
Explanation:
SUBSTRING_INDEX(Title, '@', -1)
extracts part of a string starting by the end (-1) until the @ sign.
Now for the destination page of the links, I wanted an unordered list of books for each author (many books possible for only one occurrence of names).
Here is the page template part:
<ul class="book-list cf mb4em no-list">
<txp:article_custom section="my-section" exclude="4" sort="FIELD(ID, '<txp:title />'), SUBSTRING_INDEX(Title, '@ ', -1) asc" limit="0" time="any" trim='/(@.*)/' replace><txp:output_form form="author_books" /></txp:article_custom>
</ul>
And the author_books form content:
<li><txp:variable name="name" trim><txp:title trim='/(.*\@\s)(.*)/' replace='$2' /></txp:variable><h2 id="a-<txp:php>global $variable; $str = str_replace(array(' ', ''', 'E', 'É', 'é'), array('-', '-', 'e', 'e', 'e'), $variable['name']);$str = iconv("utf-8", "ascii//TRANSLIT",$str); echo strtolower($str);</txp:php>"><txp:variable name="name" /></h2>
<txp:article_custom section="my-section" time="any" limit="0" sort="Title asc">
<txp:evaluate query='contains("<txp:title />", "<txp:variable name="name" />")'>
<ul>
<li>« <a href="<txp:permlink />"><txp:title trim='/(.*)(\@\s.*)/' replace='$1' /></a> »</li>
</ul>
</txp:evaluate>
</txp:article_custom></li>
Important note: because the website is running a 4.8.8-dev (for tests), we use the new limit="0" devs feature for unlimited.
@Julian: the js cart solution is this one (but largely altered by me) because the client didn’t need a complex process (all is governed by custom fields): https://github.com/cara-tm/minicart
Last edited by Pat64 (2021-12-13 18:00:50)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline