Plugin documentation follows this short message from our sponsor ;-)
If you like my code and find it useful, feel free to show your appreciation with something from my UK Amazon wish list (or US) or donate to the Stef Dawson community coding pot by following the Donate button below to PayPal. Thanks!
smd_write_cats
Add categories directly from the Write tab without having to visit the Categories tab first.
Author / credits
Written by Stef Dawson
Installation / uninstallation
Requires TXP 4.2.0+
Download the plugin from either textpattern.org, or the software page, paste the code into the TXP Admin -> Plugins pane, install and enable the plugin. Visit the forum thread for more info or to report on the success or otherwise of the plugin.
To uninstall, delete from the Admin -> Plugins page.
Usage
Type a comma-separated list of categories into the Or new categories box on the Write tab and when you hit Save or Publish they will be created if they don’t already exist.
You can create as many as you like (just keep comma-separating them) and only the first two will be automatically assigned to the article; replacing any categories that were already assigned. If one or both of the first two categories you type already exists they will be assigned to the article (it ignores the case when checking the database for matches).
If you want to set Category 2 only, just start your list with a comma, e.g. , My new category. Similarly, if for some reason you want to create more categories but don’t want to assign them to the current article, put two commas at the start: , , Some unlinked category, And another.
Parent categories
By default all categories you create will be stored under the ‘root’ of the article tree. If you wish to assign your new category beneath an existing category you can specify an alternative syntax:
Parent category -> New category
If the designated parent category exists, your new category will be assigned to it. If it doesn’t exist (the plugin ignores the case of the parent category) then it will be assigned to root.
You can customize the mechanism for supplying parent-child relationships by creating the following prefs (smd_prefalizer can help here):
| Pref name | Value | Visiblity | Event | Notes |
|---|---|---|---|---|
| smd_write_cats_child_first | 0=parent first 1=child first | Hidden | smdwritecats | Setting this to 1 means that you specify the new category first and then specify the parent you want it assigned to |
| smd_write_cats_parent_delim | any string | Hidden | smdwritecats | Overrides the default ->. Whatever you specify here will be used as a parent/child delimiter. Be careful to choose something that would not normally be used in a category name! |
If you create a new category, you may use that category as a parent in subsequent category declarations. For example:
Fruit, Fruit->Apple
will create the category Fruit (at the root of the tree) and assign it to Category1. It will then create Apple beneath the Fruit category, and assign it to Category2.
Changelog
- 06 Jul 10 | 0.10 | Initial release
- 11 Jul 10 | 0.20 | Added parent->child ability ; fixed ‘article’ type selection (thanks monkeyninja/Uli) ; made tests case insensitive to prevent duplicate cats being created ; prevented ‘root’ being added to category1/2 ; added
editclass to input box and made sure only people who have category privs can create them (thanks Uli)
Source code
If you’d rather wander aimlessly through thousands of lines of PHP source code, you’ll need to step into the view source page.
Legacy software
If, for some inexplicable reason, you need a prior version of a plugin, it can probably be found on the plugin archive page.
Experimental software
If you’re feeling brave, or fancy going bareback, you can test out some of my beta code. It can be found on the plugin beta page.
