Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
How do I make a simple plugin?
Hi
I’d like to make a very simple plugin that displays your name. (The reason I want to make this is because I want to learn how to make plugins for textpattern.) I know some PHP.
I want it to be something like this: <txp:123_testplugin name="Blah" /> which will output the name “Blah”.
I think it’s very simple for most of you but I have no idea how to make it.
Josie
Offline
#2 2006-08-09 13:41:32
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
Re: How do I make a simple plugin?
I am in the same boat xjosie, though I wish I had more PHP experience to fall back on..
Offline
Re: How do I make a simple plugin?
Here, this should work…..
<pre>
<code>
<?php
$plugin[‘version’] = ‘0.1’;
$plugin[‘author’] = ‘Josie’;
$plugin[‘author_uri’] = ‘http://www.whitehouse.gov’;
$plugin[‘description’] = ‘Display your name.’;
?plugin[‘type’] = 0;
@include_once(‘zem_tpl.php’);
if (0) {
?>
# —- BEGIN PLUGIN HELP —-
h1. Josie’s Name
Put this tag in:
<code> <txp:jsi_display name=”“ /> </code>
And put the name you wish to display in the name=”“ attribute.
# —- END PLUGIN HELP —-
<?php
}
# —- BEGIN PLUGIN CODE —-
function jsi_display($atts) {
global $prefs;
global $permlink_mode;
global $thisarticle;
global $img_dir;
extract(lAtts(array( ‘name’=> (!empty($prefs[‘jsi_display_name’]))?$prefs[‘jsi_display_name’]:‘No name given!’ ),$atts));
return $name
}
# —- END PLUGIN CODE —-
}
?>
</code>
</pre>
Now you just need to download the zem_tpl.php file (from here ) and compile it. (by simply loading this file in your browser from a php server.
Last edited by Walker (2006-08-09 14:33:10)
Offline
Re: How do I make a simple plugin?
Shit. That took way too many edits to get it to display the code right. Anyone (mary), is there an official Textpattern pastebin?
Offline
#5 2006-08-09 15:13:39
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: How do I make a simple plugin?
No, there isn’t, I’m afraid – at present.
Offline
Re: How do I make a simple plugin?
xjosie729, you can as well use a more “visual” way with the plugin composer. Here’s what you should do:
- install the plugin ied_plugin_composer
- in the “plugin composer” panel enter “xxx_testplugin” and hit “create new plugin”
- enter the code:
<pre>
<code>
function xxx_display($atts) {
extract(lAtts(array( ‘name’=> ‘No name given!’ ),$atts));
return $name;
}
</code>
</pre>
(Simplified Walker’s code with trailing ;)
- check “enable plugin”
- since your plugin doesn’t do anything to the admin panel you can leave “plugin uses admin side” unchecked.
- fill the other fields, or do it later (but before you decide to share your plugin with others)
- hit “save”
- test the tag: <txp:xxx_display name="Blah" />
- when you are ready to share your plugin with others, scroll down and hit save as xxx_testplugin_v0.1.txt (for distribution) link
Plugin Composer — admin plugin to write your own plugins
Offline
Re: How do I make a simple plugin?
Thanks!
Josie
Offline
Pages: 1