Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: rah_function // Every PHP function is a tag
Oh, whow!
That’s a neat thing. Thank you!
Digital nomad, sailing the world on a sailboat: 32fthome.com
Offline
Re: rah_function // Every PHP function is a tag
speeke wrote:
Great plugin, btw!
Sarah, nice to see that you like the plugin.
Could this be something to do with MySQL counts starting at 1 versus PHP starting at 0?
Don’t know what PHP starting point you are meaning, but the count starts from one; The first found row is the number one.
safe_count() function you are calling with the tag, is part of Textpattern’s core library. It runs a standard count query:
select count(*) from textpattern where Section="name"
Remember that the count also counts draws and hidden articles. If the count is rendered wrong with plain query too, and you are certain that it is wrong, the table/index might be a bit broken. Running a repair helps with that. You can use repair with phpMyadmin, for example.
If you use specialchars in the value (", ', \ etc), you need to escape the chars by using doSlash. Something like:
<txp:rah_function table="textpattern" thing="here">
foo='<txp:rah_function call="doSlash">bar</txp:rah_function>' and bar='foo'
</txp:rah_function>
Offline
#18 2010-06-21 07:39:52
- Darkliam
- New Member
- Registered: 2010-06-20
- Posts: 9
Re: rah_function // Every PHP function is a tag
Hello,
can we put this : <txp:rah_function call="safe_count" table="textpattern" where='Category="peintres"' /> for search the number of article in a category (I use rss_unlimited_categorie)
in a txp variable?
(I test that : <txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where='Category="peintres" ' />' /> but this not right.)
Added code formating -Gocom
Last edited by Gocom (2010-06-21 08:17:06)
Offline
Re: rah_function // Every PHP function is a tag
Darkliam wrote:
(I test that :
<txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where='Category="peintres" ' />' />but this not right.)
Yep, it’s not. TXP.com weblog / Tag parser – par 1: new features
The parser stops because there are ' single quotes inside single quotes. Let me give some options.
Using variable as container:
<txp:variable name="test"><txp:rah_function call="safe_count" table="textpattern" where='Category="peintres"' /></txp:variable>
Escaping the single quotes by using double single quotes:
<txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where=''Category="peintres"'' />' />
Or because the inner one doesn’t have tags used as values:
<txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where="Category=''peintres''" />' />
Or:
<txp:variable name="test" value='<txp:rah_function call="safe_count" table="textpattern" where="Category=""peintres""" />' />
Hope it helps :-)
Offline
#20 2010-06-21 09:51:08
- Darkliam
- New Member
- Registered: 2010-06-20
- Posts: 9
Re: rah_function // Every PHP function is a tag
And that can be used with rss_unlimited_category? can we used the name of the other categories create ? This plugins use always category 1 and category 2 or it accept the other categories created by rss_unlimited_category?
Offline
Re: rah_function // Every PHP function is a tag
Darkliam wrote:
And that can be used with rss_unlimited_category? can we used the name of the other categories create ? This plugins use always category 1 and category 2 or it accept the other categories created by rss_unlimited_category?
I can’t comment on that. I have no idea where or how rss_unlimited_categories stores the categories. I just basically corrected your markup, as that was what I thought you were asking.
What comes to the limits of rah_function, from the plugins pov there are none. The plugin just calls PHP functions, which means that it works as long as the returned output is a string. The actual limit comes from the function that is used.
The safe_count() you used in your example, runs a query that counts matching rows, and the limits of safe_count() are same as normal count query’s.
Offline
Re: rah_function // Every PHP function is a tag
Darkliam, I took bit of look at rss_unlimited_categories and it stores the infomation about the categories in textpattern_category table.
<txp:rah_function call="safe_count" table="textpattern_category" where="category_id=13" />
Something like that should get the count. The category_id is what you want to macth. Instead the name of the category, it uses the ID number of the category.
You can dynamically fetch the category’s ID from txp_category table too, if you required:
<txp:rah_function call="fetch" what="id" table="txp_category" where="name" is="peintres" />
Which can then be feeded to the count. Best solution tho, would be use the ID without the extra step.
Offline
#23 2010-06-21 10:58:56
- Darkliam
- New Member
- Registered: 2010-06-20
- Posts: 9
Re: rah_function // Every PHP function is a tag
I have understand what you would arrive but what I put after where=“category_id=13”? (I take the id with <txp:rah_function call=“fetch” what=“id” table=“txp_category” where=“name” is=“peintres” /> but I must put this lignes in this code?)
I test that <txp:rah_function call=“safe_count” table=“textpattern_category” where=“category_id=<txp:rah_function call=‘fetch’ what=‘id’ table=‘txp_category’ where=‘name’ is=‘peintres’ />” /> ?
Or I must use a txp:variable to put the ID?
Last edited by Darkliam (2010-06-21 11:03:30)
Offline
Re: rah_function // Every PHP function is a tag
Darkliam wrote:
I test that
<txp:rah_function call="safe_count" table="textpattern_category" where="category_id=<txp:rah_function call='fetch' what='id' table='txp_category' where='name' is='peintres' />" />?
Remember the quotes ;-). If you want to use tags inside tags with rah_function you have couple of options. Like <txp:variable />, also rah_function supports containers:
<txp:rah_function call="safe_count" table="textpattern_category" thing="here">
category_id='<txp:rah_function call="fetch" what="id" table="txp_category" where="name" is="peintres" />'
</txp:rah_function>
Or correct use of quotes:
<txp:rah_function call="safe_count" table="textpattern_category" where='category_id="<txp:rah_function call="fetch" what="id" table="txp_category" where="name" is="peintres" />"' />
Remember that only contents surrounded with single quotes will be parsed.
Offline
#25 2010-06-21 12:40:10
- Darkliam
- New Member
- Registered: 2010-06-20
- Posts: 9
Re: rah_function // Every PHP function is a tag
Ok tanks you for your help
Offline
Re: rah_function // Every PHP function is a tag
jukka thanks for this plugin first.
As explained in the plugin doc I’m using it to count the number of articles in a category, such as:
<txp:rah_function call="safe_count" table="textpattern" where='Category1="<txp:category1 />"' />
I would like to count articles this way but only count those articles with live status and exclude others. So I tryed this:
<txp:rah_function call="safe_count" table="textpattern" where='Category1="<txp:category1 />" && status="live"' />
But doesn’t work, returns for every category “0”
Any clues ?
Thanks !
Last edited by hablablow (2010-06-28 12:24:22)
_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__
Offline
Re: rah_function // Every PHP function is a tag
Hi Guillaume:
Have you tried with status="4"? That’s probably how status is stored in TXP database.
Offline
Re: rah_function // Every PHP function is a tag
Jaja !
<txp:rah_function call="safe_count" table="textpattern" where='Category1="<txp:category1 />" && status="4"' />
Working !
Gracias Julián !
_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__
Offline
Re: rah_function // Every PHP function is a tag
Hello,
Is there a way to add an attribute inside this snippet to count only articles that have an existing image. By existing, I mean an image that is recorded in the db…
<txp:rah_function call="safe_count" table="textpattern" where='Category1="<txp:category1 />" && status="4"' />
Tried this:
<txp:rah_function call="safe_count" table="textpattern" where='Category1="<txp:category1 />" && status="4" && Image="<txp:image />"' />
Unlucky :P
Thanks !
Last edited by hablablow (2011-03-22 22:33:30)
_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__
Offline
#30 2011-03-22 22:57:25
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,316
Re: rah_function // Every PHP function is a tag
Could this help:
where="image != ''" ?
I better paste my original: <txp:jmd_count table="textpattern" where="image != ''" />
Last edited by uli (2011-03-22 22:58:53)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline