Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Grabbing plugin output via PHP
Hi everyone,
I’m trying to count the number of articles in the current section, grab that count, and subtract 1 from it. This is proving difficult.
Both mdn_count and mem_article_count are great and produce the number reliably. However, because textpattern code is run after php code (I think), the following does not work:
<txp:php>
$count = "<txp:mdn_count section='#' />";
$countlessone = $count - 1;
</txp:php>
It looks like it works because echoing $count will give you the number. But if you try to do any math on it (as above), you realize that $count is really a string (with the contents <txp:mdn_count …”) and no amount of int or trim will turn it into the actual number.
Is there an easy way to dip into the plugin’s PHP and just grab the output, rather than using the Textpattern syntax? When I edit the mdn_count plugin, I can see the $rs variable there, but I don’t know how to access it. (Plugins in general appear to be PHP functions with some special relationship to Textpattern and the database, which I don’t understand.) Or do I have to write my own SQL query in PHP?
Background: the goal here is to run an article_custom call with a limit of one less than the total number of articles in the section. So I think if I can get the $countlessone variable to work, I will then be able to use this: <txp:article_custom limit='<txp:php>$countless1</txp:php> />'
Thanks so much for any advice!
Last edited by jmuspratt (2009-09-15 17:24:32)
Offline
Re: Grabbing plugin output via PHP
Try replacing the tag with
mdn_count(array('section'=>'#'))
and/or casting $count
to an integer:
$countlessone = (integer)$count - 1;
Code is topiary
Offline
Re: Grabbing plugin output via PHP
Thank you!
That was exactly my issue: I knew that if I just used the raw function I would somehow need to pass the current section to it, and I didn’t know how.
Offline
Re: Grabbing plugin output via PHP
Another way:
<txp:php>
$count = parse('<txp:mdn_count section='#' />');
$countlessone = $count - 1;
</txp:php>
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: Grabbing plugin output via PHP
Calling the tag handler function directly instead of using parse() is much faster though.
Offline
Pages: 1