Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-04-06 00:48:48

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 167
Website

Show an article count for multiple sections

I’ve found a couple of plugins that give article counts for a single section (mdn_count and mem_article_count), but I’d like to display the grand total for a number of sections. Can it be done?


Mark

Offline

#2 2009-04-08 21:22:19

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Show an article count for multiple sections

Probably using rvm_count or adi_calc in tandem with txp:article_custom, but it may imply querying the database for articles just to count them. Not sure if that is efficient or not. Hope someone can shed some light on this.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2009-04-08 21:36:20

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

Re: Show an article count for multiple sections

How about jmd_count. Or if none of the above work, you could get your hands dirty with smd_query and see if that can do it :-)


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 2009-04-08 22:04:30

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Show an article count for multiple sections

@Bloke,
thanks for sharing your knowledge.

I was looking for a solution to count articles on each section, and wouldn’t feel so comfortable using article_custom in tandem with rvm_counter/adi_calc (btw, rvm_counter as it was released won’t work1) nor mdn_count / mem_article_count (they are too old… of course, that shouldn’t mean anything, and if they get the job done, it’s enough… but really old plugins may not be taking advantage of latest TXP features or may break unexpectedly).

1 This modified version of rvm_counter counts things for each hit to the page. The original one counts things on the database, so concurrent hits may affect the count.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#5 2009-04-09 17:19:50

geoff777
Plugin Author
From: Benarrabá Andalucía Spain
Registered: 2008-02-19
Posts: 282
Website

Re: Show an article count for multiple sections

Hi I needed this a week or so ago.

I made a form called article_count containing one line … <txp:adi_calc name=“article_count” add=“1” />

Then use …

<txp:variable name=“article_count” value=“0” />
<txp:article_custom section=“your_section_name” form=“article_count”/>

Geoff


There are 10 types of people in the world: those who understand binary, and those who don’t.

Offline

#6 2009-04-10 01:24:39

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 167
Website

Re: Show an article count for multiple sections

Thanks, guys, I’ll try out some of your ideas. I’ll be totally lost if I have to do anything with the database, though.


Mark

Offline

#7 2009-04-10 01:56:06

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Show an article count for multiple sections

there is also mdn_count which I’ve been using for a few years now without any problems.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Online

#8 2009-04-10 19:19:22

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 167
Website

Re: Show an article count for multiple sections

I have not been able to find a way of using mdn_count to total the count for more than one section. That is, putting in the names of more than one section does not work.


Mark

Offline

#9 2009-04-11 07:17:32

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Show an article count for multiple sections

mwr wrote:

I have not been able to find a way of using mdn_count to total the count for more than one section. That is, putting in the names of more than one section does not work.

Did you try just using <txp:mdn_count />? Without the section or category parameters which are optional anyway, it should count all articles.

> Edit : I did not test it but if you want to add the articles from a number of sections wouldn’t something like

<txp:php>echo ('<txp:mdn_count section="section1"/>' + '<txp:mdn_count section="section2"/>')</txp:php> work? Maybe someone with programming skills will help here.

Last edited by colak (2009-04-11 08:08:14)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Online

#10 2009-04-11 21:42:55

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Show an article count for multiple sections

colak wrote:

<txp:php>echo ('<txp:mdn_count section="section1"/>' + '<txp:mdn_count section="section2"/>')</txp:php> work? Maybe someone with programming skills will help here.

If you’re using tags in PHP, you need to use the functions or parse them. So this may be what you want (untested – unfamiliar with mdn_count):

<txp:php>
echo mdn_count(array('section' => 'section1'))
     + mdn_count(array('section' => 'section1'));
</txp:php>

Note: Although jmd_count shares some of the same features, it’s a little more flexible and efficient than mdn_count. For this example, it’d be:

<txp:php>
echo jmd_count(
    array('table' => 'textpattern', 
          'where' => 'Section in("articles", "about")'
    ));
</txp:php>

Last edited by jm (2009-04-11 21:43:44)

Offline

#11 2009-04-11 23:10:16

mwr
Member
From: Canada
Registered: 2006-01-31
Posts: 167
Website

Re: Show an article count for multiple sections

Brilliant — thanks, jm.


Mark

Offline

Board footer

Powered by FluxBB