Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-11-16 18:17:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Count articles in a section

I thought this might work:

<txp:variable name="article_count" trim>
  <txp:article_custom section='<txp:section />' fields="ID" pgonly pageby limit="999" status><txp:yield item="count" /></txp:article_custom>
</txp:variable>

Alas, it always assigns 1 to the variable. I’m clearly missing something obvious. Any pointers greatly appreciated.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2021-11-16 18:51:13

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

Re: Count articles in a section

When fields is set, the counters are reset for each group:

<txp:article_custom fields="section" limit="999" status>
    <txp:custom_field name="section" /> (<txp:yield item="count" /> articles)
</txp:article_custom>

I think you can get what you need like this:

<txp:variable name="article_count" trim>
  <txp:article_custom section='<txp:section />' pgonly status />
</txp:variable>

Offline

#3 2021-11-16 19:12:23

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Count articles in a section

Hmm, thanks. Makes sense that field counts reset at each change of grouping (I should have picked up on that myself, duh) but your suggestion still yields 1 for me even though there are two articles in the section I’m viewing.

Maybe I need to employ add? EDIT: Nope.

Last edited by Bloke (2021-11-16 19:16:55)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2021-11-16 20:08:42

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

Re: Count articles in a section

Maybe you need to set pageby="1" (or limit="1"?), sorry.

Offline

#5 2021-11-16 20:13:43

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Count articles in a section

Ah, I tried valueless pageby earlier, which didn’t work, but pageby="1" does.

Thank you so much.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2021-11-16 20:17:39

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

Re: Count articles in a section

Bloke wrote #331982:

Ah, I tried valueless pageby earlier, which didn’t work, but pageby="1" does.

Yep, the valueless one is for (re)setting the pagination data, paged by limit(?)

Offline

Board footer

Powered by FluxBB