Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-09-24 19:19:10

Manhog
Member
From: Manchester, UK
Registered: 2004-03-15
Posts: 24

How to use forms in my plugin?

Hello,

I’m currently redeveloping an old a site to use TXP 4.0.5 (it was 4.0.4). As one of the most important plugins for the site is not working for me with 4.0.5 at the moment (chh_related_articles), I’ve decided to write my own plugin that gives me the limited functionality I need.

I have a little experience of writing plugins, but most of the them have been variations on the ‘do an SQL query, loop throught the results, parse them as HTML and spit them out directly to the browser’ kind.

With this plugin I need to figure out how to get a list of article IDs rendered using a particular form, rather than just parsing the results as HTML myself.

But I’m really stuck here as I can’t find any documentation that explains that process.

Is there an existing TXP function that I can call and say to it, loop through this list of article IDs and render them using form ‘X’ (if that makes sense)?

Anyone know of anything I can read to help me, apart from trawling through the source code of other plugins?

Apologies if the answer is staring me in the face.

Thanks,
Alan.

Offline

#2 2007-09-24 19:20:32

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

Re: How to use forms in my plugin?

Look at how the doArticles function in /textpattern/publish.php does this.

Offline

#3 2007-09-24 20:41:47

Manhog
Member
From: Manchester, UK
Registered: 2004-03-15
Posts: 24

Re: How to use forms in my plugin?

ruud wrote:

Look at how the doArticles function in /textpattern/publish.php does this.

Thanks, ruud. Not too sure if I’m doing it right, but I’ve managed to pull in one article by doing this…

$articles = array ('form' => $form, 'id' => $related);
return doArticles($articles, true);

In the above, $related is a string with a value something like ’23,54,64’. Is that how I pass a list of article IDs to doArticle or should that be an array?

Also, when I have my plugin tag twice in the same page it renders the second one OK, but doesn’t render the first one as it seems to ‘forget’ all the variables in the plugin. Do I somehow have to reset my plugin for it to work twice on the same page without any problems?

Sorry for the all questions. Thanks for your help so far.

Alan.

Offline

#4 2007-09-24 20:54:50

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

Re: How to use forms in my plugin?

That’s not what I meant.
doArticles fetches article data from the database, populates article data, parses an article form.
Assuming you want to do something doArticles cannot do, you’ll have to do something similar yourself (not by calling the doArticles function, but by getting inspiration from how it does its job to build your own function).

doArticles is the function that does the most work as a taghandler for both txp:article and txp:custom when in article list mode.

Offline

Board footer

Powered by FluxBB