Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: mdn_count
Gallex wrote:
working, and very well! thank’s colak!
but could you provide code for: display total number of articles under those sections: houses, farms, apartments, lands, commercial real estate, rent, as well?
Try <txp:php>echo safe_count('textpattern', 'Status = 4');</txp:php>
>Edit: the above code lists all published live articles
Alternatively I’m not sure if the plugin supports a comma delimited list
<txp:mdn_count section="houses,farms,apartments,lands,commercial-real-estate,rent">
Last edited by colak (2012-04-07 14:41:59)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#92 2012-04-09 10:51:30
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,331
Re: mdn_count
plugin doesn’t support comma delimited list of sections, sadly.
but, is it possible to add sections attribute to your php code?
Offline
#93 2012-04-10 03:09:41
- radneck
- Plugin Author
- Registered: 2005-07-03
- Posts: 109
Re: mdn_count
Gallex wrote:
plugin doesn’t support comma delimited list of sections, sadly.
Actually it should – is this not working for you?
Offline
#94 2012-04-10 07:00:07
- Gallex
- Member
- Registered: 2006-10-08
- Posts: 1,331
Re: mdn_count
juhhuu! i used not the very newest (1.4) version ;)
Offline
#95 2013-08-05 17:36:00
- gfdesign
- Member

- From: Argentina
- Registered: 2009-04-20
- Posts: 401
Re: mdn_count
Hi. I have a trouble with this plugin. It has left to work to me.
I want to show the number of articles of the current category, but always I get zero.
I’ve tried with:
<p><txp:mdn_count category="#" status="4" /></p> but I get <p>0</p>
<p><txp:mdn_count category="<txp:category />" status="4" /></p> but I get <p>0</p>
<p><txp:mdn_count category="<txp:category1 />" status="4" /></p> but I get <p>0</p>
However, when I specify a category by its name, I get the correct value. For example:
<p><txp:mdn_count category="fruits" status="4" /></p> I get <p>15</p>
I aim to show a message when no there loaded articles in that category, so I can’t make a conditional rule through that.
Any idea?
Offline
Re: mdn_count
Look out for the quotes
<p><txp:mdn_count category='<txp:category />' status="4" /></p>
<p><txp:mdn_count category='<txp:category1 />' status="4" /></p>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#97 2013-08-05 19:54:11
- gfdesign
- Member

- From: Argentina
- Registered: 2009-04-20
- Posts: 401
Re: mdn_count
Thanks. That works!
However, now I can’t achieve the below conditional that I created.
What could be the problem?
Regards
<txp:variable name="total" value="<txp:mdn_count category='<txp:category />' status='4' />" />
<p>Articles in this category: <txp:variable name="total" /></p> <!-- this variable displays correctly -->
<txp:if_variable name="total" value="0"> <!-- this condition, never is fulfilled -->
<h3>NO LOADED PRODUCTS IN THIS CATEGORY</h3>
</txp:if_variable>
Offline
Re: mdn_count
This shouldn’t have worked:
<txp:variable name="total" value="<txp:mdn_count category='<txp:category />' status='4' />" />
As colak already mentioned, you have to escape the quotes when using txp tags inside txp tags. And here, you are using txp tags inside txp tags inside txp tags, so you have to escape each level.
<txp:variable name="total" value='<txp:mdn_count category=''<txp:category />'' status='4' />' />
Notice that here category=''<txp:category />'' I’ve typed two single quotes ' (and not a double quote ").
Offline
#99 2013-08-05 21:19:46
- gfdesign
- Member

- From: Argentina
- Registered: 2009-04-20
- Posts: 401
Re: mdn_count
Thanks Maniqui, but the problem here is not keep the value into the variable, in fact it works well. The problem is the condition never is fulfilled.
I am not be able to display a message when no there articles in a specific category.
How would you do? Is some wrong in my code?
Offline
#100 2013-08-05 22:43:09
- radneck
- Plugin Author
- Registered: 2005-07-03
- Posts: 109
Re: mdn_count
Either the quotes are still slightly off, or the category actually has no posts (try dumping out articles on the pages to test). If nothing else works, maybe use smd_if.
Offline
#101 2013-08-06 00:12:58
Re: mdn_count
First, just to keep any quoting-related issue out of this, you can rewrite this:
<txp:variable name="total" value="<txp:mdn_count category='<txp:category />' status='4' />" />
to this:
<txp:variable name="total"><txp:mdn_count category='<txp:category />' status='4' /></txp:variable>
Yes, we are still having one tag-in-tag, but well, brain hurts a little less in this second version.
Second, can you confirm that this <txp:mdn_count category='<txp:category />' status='4' /> outputs 0?
Third, have you tried explicitly assigning 0 to the variable? Like this:
<txp:variable name="total">0</txp:variable>
And then check if the condition is triggered.
If that last one attempt doesn’t work, I’d say that the issue is that 0 is a falsy value, and it’s somehow short-circuiting the logic you are trying to implement.
(Textpattern internals seems to suggest that).
So, here is a workaround for this problem.
<txp:variable name="total"><txp:mdn_count category='<txp:category />' status='4' /></txp:variable> <!-- this variable will store a number, it can be 0, 1, 2, 3... etc -->
<txp:variable name="total_string">total_<txp:variable name="total" /></txp:variable> <!-- this variable will store a string, it can be "total_0", "total_1", "total_2"... etc -->
<p>Articles in this category: <txp:variable name="total" /></p> <!-- this variable displays correctly -->
<txp:if_variable name="total_string" value="total_0">
<h3>NO LOADED PRODUCTS IN THIS CATEGORY</h3>
</txp:if_variable>
Offline
#102 2013-08-06 04:41:08
Re: mdn_count
There is another method you could use
<txp:variable name="checkarticles" value='<txp:article_custom category=''<txp:category />'' limit="1" />' />
<txp:if_variable name="checkarticles" value="">
<h3>NO LOADED PRODUCTS IN THIS CATEGORY</h3>
<txp:else />
<p><txp:mdn_count category='<txp:category />' status="4" /></p>
</txp:if_variable>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#103 2013-08-06 12:18:33
- gfdesign
- Member

- From: Argentina
- Registered: 2009-04-20
- Posts: 401
Re: mdn_count
Guys, many thanks for your suggestions. Both work for me!
Finally, my code was like this:
<txp:variable name="total"><txp:mdn_count category='<txp:category />' status='4' /></txp:variable>
<txp:if_variable name="total" value="0">
<h3>NO LOADED PRODUCTS IN THIS CATEGORY</h3>
</txp:if_variable>
About Maniqui’s question
Third, have you tried explicitly assigning0to the variable? Like this:
<txp:variable name="total">0</txp:variable>
Yes, and the conditional is met here. Surely, it was a quoting-related issue as you said. Although, I couldn’t understand why it didn’t work, since I displayed the variable’s value and it was correct when I tried in my way. :/
Anyways, I am thankful for your invaluable help.
Best regards
Offline
#104 2013-09-09 02:03:10
- radneck
- Plugin Author
- Registered: 2005-07-03
- Posts: 109
Re: mdn_count
Just a quick note to say that version 2.2 of this plugin is out, now supporting filtering by custom fields.
This will likely be the last feature release for this plugin.
Bug reports always welcome.
{Edited to rectify link. – Uli}
Last edited by uli (2013-09-09 10:19:18)
Offline
#105 2016-09-30 00:25:42
- msome
- Member
- Registered: 2015-09-16
- Posts: 40
Re: mdn_count
Hi.
Need support
In new version 4.6.0, does not work
(<txp:mdn_count section='<txp:section />' />)
Result: ()
Empty parentheses
If the plugin does not work anymore, but you need an alternative solution
Important..
______________A little bit later______________
I tried the old version of the plugin 1.4
mdn_count v.1.4 – Working
mdn_count v.2.2 – Does not work
Last edited by msome (2016-09-30 00:48:45)
Offline