Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-12-08 13:56:03

From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 73

How does one make a plugin?

I’m a longtime Textpattern user and I have a confession: I haven’t the slightest clue on how to make a plugin.

I have some PHP which works fine for me but I think would make for a good tutorial. Could someone walk us through how this little bit of code becomes a plugin?

The code makes your keywords clickable and displays the related articles.

Linkable Keywords
$section = "tagged";  
$keywords = parse('<txp:keywords/>');
$keyworks = explode(",", $keywords);
echo '<ul>';
foreach($keyworks as $keywork) {
    $keywork = trim($keywork);
     echo '<li><a href="/' . $section . '/?keyword=' . $keywork .'">' . $keywork . "</a></li>";
echo '</ul>';

Then over on your page in your section, this is used to display the clicked keywords:

<txp:article_custom keywords='<txp:page_url type="keyword" />' limit='10' form='keyword_results' sort = 'Posted desc'/>

I’m sure that I would not be the only one who would appreciate a tutorial, not just in making plugins but also adopting old ones.

Last edited by amordecosmos (2020-12-08 14:14:09)


#2 2020-12-08 15:01:15

From: Leeds, UK
Registered: 2006-01-29
Posts: 9,977

Re: How does one make a plugin?

Nice idea for a public plugin. If I’ve done my job properly, all the plugin-creation resources should be available at:


Hopefully that’ll give you a leg-up, but if you find anything lacking or broken or unclear, just holler.

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp


#3 2020-12-08 16:05:47

From: Germany
Registered: 2005-01-20
Posts: 4,026

Re: How does one make a plugin?

Nice idea! You might find you can achieve what you want with rah_repeat (or here) or smd_each which allow you to loop over a string.

With rah_repeat, for example, you might do:

<txp:rah_repeat value='<txp:keywords trim />' wraptag="ul" break="li">
    <a href="/tagged?keyword=<txp:rah_repeat_value />"><txp:rah_repeat_value escape="title" /></a>

or something along those lines. Note the use of single quotes when using the output of a tag as the attribute value.

You can find a compiled version of rah_repeat v2 here (the plugin author prefers installing via composer and no longer provides the compiled txt installer files).

TXP Builders – finely-crafted code, design and txp


Board footer

Powered by FluxBB