Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Today 08:04:40

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

[Solved] 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 16:06:51)


Patrick.

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

Offline

#2 Today 08:46:34

etc
Developer
Registered: 2010-11-11
Posts: 5,519
Website GitHub

Re: [Solved] 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

#3 Today 09:03:50

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

Re: [Solved] 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

#4 Today 09:15:35

etc
Developer
Registered: 2010-11-11
Posts: 5,519
Website GitHub

Re: [Solved] 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

#5 Today 09:23:33

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

Re: [Solved] 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

#6 Today 09:39:37

etc
Developer
Registered: 2010-11-11
Posts: 5,519
Website GitHub

Re: [Solved] 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

#7 Today 09:45:27

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

Re: [Solved] 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

Board footer

Powered by FluxBB