Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Article Count
My project (and many others that I maintain) have a requirement where data(articles) needs to have a visible count or number displayed on the frontend of the site. I’ve been using mdn_count for quite a while and since upgrading to TXP 4.6X it has stopped working.
I’m not a big fan of using plugins for this reason. I’ve since had to downgrade to v1.4 of mdn_count to get it working again, so I lose newer features.
Is there ANY other way to get a native article count in TXP like the way mdn_count works? The logic exists as seen in the Categories section… it shows the article count based on the category.
Things I’m looking to accomplish:
1. A total article count.
2. Article count based on section.
3. Article count based on category.
This is basic stuff in pretty much any other CMS. I love Textpattern and don’t want to switch, but I am already 50% done converting all my TXP logic over to Symphony CMS because an article count is as simple as <xsl:value-of select="count()" />
.
Is there something I’m overlooking, is my terminology incorrect? Is there an easier way to accomplish what I’m looking for?
Offline
Re: Article Count
I guess the forthcoming txp:evaluate tag might be able to do the job. But Oleg is the expert on this one:)
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: Article Count
In the meantime, edit the plugin. Find the line that mentions NULLDATETIME and replace it with this:
$q[] = $andor.' (Posted <= now() and (now() <= Expires or Expires IS NULL))';
Untested, but it should work.
If there’s an issue with getting counts from Txp natively, just raise an issue and we’ll add tags to do it. I’ve never had to do it and didn’t realise it was a “basic” requirement, hence it’s not been done.
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
Re: Article Count
Bloke wrote #302825:
If there’s an issue with getting counts from Txp natively, just raise an issue and we’ll add tags to do it. I’ve never had to do it and didn’t realise it was a “basic” requirement, hence it’s not been done.
Thanks for the info.
When you say “raise an issue”, do you mean on GitHub?
Offline
Re: Article Count
qrayg wrote #302826:
When you say “raise an issue”, do you mean on GitHub?
Yep – here: github.com/textpattern/textpattern/issues/new
Online
Re: Article Count
qrayg wrote #302823:
This is basic stuff in pretty much any other CMS. I love Textpattern and don’t want to switch, but I am already 50% done converting all my TXP logic over to Symphony CMS because an article count is as simple as
<xsl:value-of select="count()" />
.
A patch already exists in 4.7 to enhance <txp:article_custom />
with count functionality. Symphony way is possible with etc_query
too, but if you only need to count articles, without outputting them, it is sub-optimal (in Symphony too).
Offline
Re: Article Count
Sorry about the terseness of my reply. I was on my way out the door and just threw my answer out there.
I wasn’t being flippant or anything, it’s just that the reason it’s not been done so far has been the perceived lack of people asking for the functionality. Maybe mdn_count has satisfied people all these years, which is why few have asked for it!
Anyway, as etc says, whichever method you choose, you do need to be careful to do it in an optimal way or you could hurt your user’s experience with an expensive query.
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
Re: Article Count
It doesn’t really address the issue of going plugin-free but an alternative using adi_calc (which was updated for the 4.6 tag registry) is:
<txp:variable name="article-count" value="0" />
<txp:article_custom section="[articles]" category="[articles]" limit="9999">
<txp:adi_calc name="article-count" add="1" />
</txp:article_custom>
Offline
Re: Article Count
michaelkpate wrote #302830:
It doesn’t really address the issue of going plugin-free but an alternative using adi_calc (which was updated for the 4.6 tag registry) is:
<txp:variable name="article-count" value="0" />...
Thank you, michaelkpate… I was actually looking at adi_calc and smd_query to accomplish my goal. This example was VERY helpful. I truly appreciate it.
Offline
Offline
Re: Article Count
FYI, in 4.7 one will be able to count articles with
<txp:article_custom pgonly pageby="1" ... />
This is way more efficient than any limit="9999"
construction, which should be avoided whenever possible.
Offline
Re: Article Count
I have recently discovered that <txp:search_result_count />
does not require the search mode to output the number of articles. Just put it after <txp:article />
. Now, if it had pageby
attribute, it could output the number of pages too. Actually, it already does in my local install… worth committing to GitHub?
Offline