Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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
Re: count the number of articles
jakob wrote #318273:
Great! Just so we know: which of the two suggestions worked for you?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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
Re: count the number of articles
Indeed. Implemented! Search for your name here :)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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
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 restatus
.
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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
Re: count the number of articles
etc wrote #318288:
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.
Excellent! And makes sense. Thanks for clarifying.
TXP Builders – finely-crafted code, design and txp
Offline
Re: count the number of articles
This works perfectly. Thank you very much!
One question:
How can I add a comma as a thousands separator for the resulting number?
“6,357 images” instead of “6357 images”
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline