Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-09-15 17:23:46

jmuspratt
Member
From: Nashville, TN
Registered: 2004-10-27
Posts: 54
Website

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

#2 2009-09-15 17:38:06

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#3 2009-09-15 17:41:11

jmuspratt
Member
From: Nashville, TN
Registered: 2004-10-27
Posts: 54
Website

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

#4 2009-09-15 18:21:43

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

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

#5 2009-09-15 19:01:07

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Grabbing plugin output via PHP

Calling the tag handler function directly instead of using parse() is much faster though.

Offline

Board footer

Powered by FluxBB