Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

amordecosmos
Plugin Author
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 106
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: 11,269
Website GitHub

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,595
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

#4 2021-03-24 14:53:33

peterj
Member
From: Melbourne, Australia
Registered: 2005-06-02
Posts: 99

Re: How does one make a plugin?

I’d just been looking for something that would let me step through keywords without resorting to trusty old tru_tags, so thanks. I’ll play with your code amordecosmos & Jakob.

I had been wondering though if the keywords tag was capable of this out of the box since 4.7, as it says it is now available as a container tag? Maybe I’ve misunderstood that usage, I can’t find an example.

Could it/ can it be made to do something like txp:images..?

<txp:keywords break="li" wraptag="ul">
Something done with each <txp:keyword />
</txp:keywords>

Offline

#5 2021-03-24 15:11:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: How does one make a plugin?

peterj wrote #329434:

I had been wondering though if the keywords tag was capable of this out of the box since 4.7, as it says it is now available as a container tag?

If you can wait for Txp 4.8.5 – hopefully any day soon – then break becomes a global attribute and your example should be possible. Untested.

Heads-up: we’re going to be repurposing the keywords field in a future Txp version as actual tags, just like you’re suggesting. That field has had its day as an SEO keyword field so we figured we might as well put it to good use as a tag list.


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

#6 2021-03-24 15:23:20

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: How does one make a plugin?

Hmm, I guess the docs take our plans for reality here. You can already call <txp:keywords break="li" wraptag="ul" />, but not yet Something done with each <txp:keyword />, it’s still a single tag in 4.8.4 (and even 4.8.5).

The plans were to allow splitting any string (by comma or other delimiter) with a help of new <txp:list /> tag and access its elements with something like <txp:item />. Global break in 4.8.5 allows splitting, but does not (yet) provide an access to the chunks.

Offline

#7 2021-03-24 15:34:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: How does one make a plugin?

Ahhh drat, you’re right, Oleg. Forgot about that and didn’t think it through before replying.


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

#8 2021-03-24 15:42:43

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: How does one make a plugin?

Bloke wrote #329436:

Heads-up: we’re going to be repurposing the keywords field in a future Txp version as actual tags

That’s probably why we have decided to wait with lists. And rah_repeat is there anyway.

Parsing chunks is tricky to implement globally, since some tags already do it before wrapping, and we wouldn’t like to parse them (say, in doWrap()) twice.

Offline

#9 2021-03-24 15:55:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: How does one make a plugin?

etc wrote #329441:

Parsing chunks is tricky to implement globally, since some tags already do it before wrapping, and we wouldn’t like to parse them (say, in doWrap()) twice.

Yes it’ll have to be done at the tag level, I expect, for this very reason. I was thinking of either:

a) (cheap) leave keywords field as now (although that would have a limit of 255 chars). Split at comma.
b) (more expensive) make it a built-in custom field when unlimited CFs land, with a larger width. Split at comma.
c) (best) siphon them off to a separate tags table on upgrade, use a link table to map them, and permit synonyms via a third table. Keywords field (on-screen) is just a list of actual tags in these tables linked to the article. Auto-complete optional as you enter others.

For those interested:

  • The textarea could remain (just rebranded “Tags” and maybe moved to a different area of the Write panel) and become an input mechanism for tags.
  • The keywords column in the textpattern table could be removed, saving row space.
  • The <txp:keywords /> tag should still output the list of tags associated with the article as a comma-separated list, for backwards compatibility. This tag would become a specific article-centric metadata-outputting wrapper for a general-purpose <txp:list> tag.
  • The <txp:if_keywords> tag would return true if there were any tags associated with the article. This tag would become a specific article-centric wrapper for a general-purpose <txp:if_tag> (or <txp:if_item> or something) container.

EDIT: for reference, this is discussed in Issue 1121, and it has a link to a draft spec in the comments.

That’s probably why we have decided to wait with lists.

Yes! See above.

Last edited by Bloke (2021-03-24 16:27:49)


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

Board footer

Powered by FluxBB