Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Count a same occurrence into titles
I want to count my articles based on a single occurrence.
My article titles are all based on this format:
XXXX Yes OOOO
YYYY No RRR
ZZZ Yes MMMMM
So my goal is to count the number of times “Yes” occurs.
I tried using the fields
attributes but without any results:
<txp:article_custom section="my-section" fields="(Title, LIKE'%<txp:variable name="string" />%')" limit="0">
...
</txp:article_custom>
Note: the TXP variable stores the string extracted from a REGEX.
I think there’s a solution. Could you help me, please?
Last edited by Pat64 (Today 08:25:51)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Count a same occurrence into titles
Hi Patrick,
If you just want to count articles, the simplest solution (assuming url_title
follows the same format) is
<txp:article_custom url_title="% yes %" pgonly pageby="1" />
or
<txp:article_custom url_title='%<txp:variable name="string" />%' pgonly pageby="1" />
Offline
Re: Count a same occurrence into titles
I’m sorry, but that not works (nothing appears)…
Maybe because the string has two words (i.e. Yes Yes: First and last name)?
Last edited by Pat64 (Today 09:05:08)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Count a same occurrence into titles
Ah, ok, you should probably remove the surrounding spaces; url_title="%yes%"
, look at url_title
of your articles.
Offline
Re: Count a same occurrence into titles
Yep.
I made this changes (but without any results…):
<txp:variable name="string" trim="/\s+/" replace='-' escape="lower" />
<txp:article_custom url_title='%<txp:variable name="string" />%' pgonly pageby="1" />
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Count a same occurrence into titles
If you use 4.9, there was a silly bug that I have just patched (thanks to your question), so download txplib_publish.php
again. In 4.8.8 it should work as is.
Offline
Re: Count a same occurrence into titles
Thanks a lot, Master 🙏
(I’ll try this afternoon)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Pages: 1