Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2020-12-08 13:56:03
- amordecosmos
- Member
- From: London (Hometown: Vancouver)
- Registered: 2004-08-03
- Posts: 73
- Website
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
<txp:php>
$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>';
</txp:php>
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)
Offline
#2 2020-12-08 15:01:15
- Bloke
- Developer
- From: Leeds, UK
- Registered: 2006-01-29
- Posts: 9,977
- Website
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:
docs.textpattern.com/development/
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
Offline
#3 2020-12-08 16:05:47
- jakob
- Admin
- From: Germany
- Registered: 2005-01-20
- Posts: 4,026
- Website
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>
</txp:rah_repeat>
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
Offline
Pages: 1