Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-05-28 05:48:30

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,320
Website

count the number of articles

I’m trying to figure out how to count the number of live+sticky articles per section and the whole site.

I tried <txp:article_custom section='<txp:section />' status="live,sticky" pageby="1" pgonly /> and <txp:article_custom section="list,of,sections" status="live,sticky" pageby="1" pgonly /> but the sticky articles are not counted. Is there a vanilla way?


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#2 2019-05-28 07:49:10

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,510
Website

Re: count the number of articles

Two ideas: what happens if you use just status with no value. If I’ve understood that correctly from other threads, omitting the value means it counts both (or all?) statuses, but I’m not sure if that applies just to txp:article and not to txp:article_custom:

<txp:article_custom section="list,of,sections" pageby="1" pgonly status />

I think using pgonly bypasses the default limit value of 10, but if not, you may need to set limit="9999" too.

The other way might be to do the article count for each status and add the result together using variables.

<txp:variable name="article_count" value='<txp:article_custom section="list,of,sections" pageby="1" pgonly status="live" />' />
<txp:variable name="article_count" add='<txp:article_custom section="list,of,sections" pageby="1" pgonly status="sticky" />' />
<!-- then output it where you need it -->
<txp:variable name="article_count" />

Do either/both of those work?


TXP Builders – finely-crafted code, design and txp

Offline

#3 2019-05-28 10:01:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,320
Website

Re: count the number of articles

^^ that did the trick! For learning purposes, I wonder if it will be less load on the server if the evaluate tag is used.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#4 2019-05-28 14:56:13

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,510
Website

Re: count the number of articles

colak wrote #318262:

^^ that did the trick!

Great! Just so we know: which of the two suggestions worked for you?

For learning purposes, I wonder if it will be less load on the server if the evaluate tag is used.

You may be onto something there. Oleg can probably say…?


TXP Builders – finely-crafted code, design and txp

Offline

#5 2019-05-28 15:09:49

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,320
Website

Re: count the number of articles

jakob wrote #318273:

Great! Just so we know: which of the two suggestions worked for you?

I implemented it in to ways here and here.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#6 2019-05-28 15:43:29

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,510
Website

Re: count the number of articles

Just a small minor-tweak: if you want to output the variable’s valuable immediately where you’ve defined or calculated it, you should be able to simply add output (or output="1") to the tag with the add attribute and drop the extra list item. That attribute was added in txp 4.7.2.


TXP Builders – finely-crafted code, design and txp

Offline

#7 2019-05-28 16:07:19

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,320
Website

Re: count the number of articles

Indeed. Implemented! Search for your name here :)


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#8 2019-05-29 05:06:26

etc
Developer
Registered: 2010-11-11
Posts: 3,287
Website

Re: count the number of articles

<txp:article_custom section="list,of,sections" status pgonly pageby="1" />

should be fine. I don’t remember why we have not implemented status="live, sticky" too. Probably because it would be not bw-compatible (though the risk is minimal) and Stef had some further plans re status.

Offline

#9 2019-05-29 05:47:02

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,320
Website

Re: count the number of articles

etc wrote #318282:

<txp:article_custom section="list,of,sections" status pgonly pageby="1" />...

should be fine. I don’t remember why we have not implemented status="live, sticky" too. Probably because it would be not bw-compatible (though the risk is minimal) and Stef had some further plans re status.

Hi Oleg,

Indeed it does although it is slightly counter-intuitive as it does not explicitly tell us that it will omit draft and pending statuses.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#10 2019-05-29 08:06:32

etc
Developer
Registered: 2010-11-11
Posts: 3,287
Website

Re: count the number of articles

colak wrote #318283:

Indeed it does although it is slightly counter-intuitive as it does not explicitly tell us that it will omit draft and pending statuses.

The idea was to select all articles having a “visible” status, be it live, sticky or some future one. You can not output “hidden” statuses anyway, by privacy concern.

Offline

Board footer

Powered by FluxBB