Documentation for the Textpattern plugin smd_write_cats by Stef Dawson 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, either via paypal.me/stefdawson by following the Donate button below to PayPal. Thanks!
Add article, image, file or link categories directly when creating content, without having to visit the Categories tab first.
Installation / uninstallation
Requires Textpattern CMS 4.4.1+
Download the plugin from either textpattern.org, or the software page, paste the code into the Txp Admin->Plugins panel, 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.
Type a comma-separated list of category titles into the Or new categories box 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. On the Write panel, 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 category titles you type already exists they will be assigned to the article (it ignores the case when checking the database for matches, but the category title will be created exactly as you typed it). The plugin functions in a similar manner on the Images, Files and Links panels, except only the first category will be assigned.
For articles, if you want to set Category 2 only, just start your list with a comma, e.g.
, My new category. 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. The same goes for the other content types, but you only need to specify one empty comma.
By default all categories you create will be stored under the ‘root’ of the category 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 title exists, your new category will be assigned to it. If it doesn’t exist (the plugin ignores the case of the parent category title) then it will be assigned to root. IMPORTANT: although the case doesn’t matter, the parent must match your category Title (not-its-sanitized-name) for it to be assigned beneath it.
You can customize the mechanism for supplying parent-child relationships by creating the following prefs (smd_prefalizer can help here):
|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 |
If you create a new category, you may use that category as a parent in subsequent category declarations. For example:
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.
Author / credits
Written by Stef Dawson
- 06 Jul 2010 | 0.10 | Initial release
- 11 Jul 2010 | 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)
- 13 Jun 2012 | 0.30 | Extended for image, file and link categories ; made parent category assignment more lenient to case (both thanks MattD)
If you’d rather scrabble amid the ones and noughts, you’ll need to step into the view source page.
If, for some inexplicable reason, you need a legacy version of a plugin, it can probably be found on the plugin archive page.
If you’re feeling brave, or fancy skateboarding into volcanos, you can test out some of my beta code. It can be found on the plugin beta page.