Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2021-12-06 06:43:59

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

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

#14 2021-12-06 16:22:23

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,236
Website

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

#15 2021-12-06 18:33:36

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

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(' ', '&#39;', '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(' ', '&#39;', '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>«&#8202;<a href="<txp:permlink />"><txp:title trim='/(.*)(\@\s.*)/' replace='$1' /></a>&#8202;»</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

#16 2021-12-07 04:43:13

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

Re: [Solved] Extraction for all articles containing a unique title string

The only difficulty that I encounter: I can’t sort ascendant inner results (books list)… (not really a problem, just a refinement) .

Edit: Nope. It works (tested with 4.8.8-dev; code above corrected).

Last edited by Pat64 (2021-12-13 18:02:56)


Patrick.

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

Offline

#17 2021-12-07 11:14:40

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,236
Website

Re: [Solved] Extraction for all articles containing a unique title string

Pat64 wrote #332098:

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…

Thanks for the detailed description. I’m going to have study that more carefully when I have more time because I think that situation could come up in other constellations.

One thing I did wonder about, though: was there a particular reason why you didn’t put the author name in a custom field, and then use that to filter the book / author lists?

I have a possible potential site with an ancient (2004) database where the “work” and “author” are in separate tables and linked. I worked out a way one could filter in both directions, though it requires more database queries. One could, however, solve that possible speed-bump by caching the results.

@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

Nice. Something else to look at in more detail. Thank you!


TXP Builders – finely-crafted code, design and txp

Offline

#18 2021-12-07 13:01:24

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

Re: [Solved] Extraction for all articles containing a unique title string

jakob wrote #332112:

[…]
One thing I did wonder about, though: was there a particular reason why you didn’t put the author name in a custom field, and then use that to filter the book / author lists?
[…]

For simplification to the client. There are already enough, a lot of custom fields in use (the sign @ do not affect permalinks structure, otherwise it was a bad choice).

Last edited by Pat64 (2021-12-07 13:07:02)


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