[wp-hackers] Best pratice categories ordering
The WordPress Web Warlock
wordpress at web-warlocks.net
Thu Jun 16 08:28:37 UTC 2011
Al 15/06/2011 16:06, En/na Leo Baiano ha escrit:
> To avoid compatibility problems in future it would be interesting, instead
> of creating afield in the table, create a relationship table?
A plugin I'm working in (neither released) uses term metadata for that
(and other features). That is, I'm adding just a single term_meta table
for a bunch of things.
I prefer to add a single multiuses table, whose rows and data can be
cached and processed at init, than a field in an existing table; or
worse, using a brand new table for each feature added.
Besides, this way I can add different order fields or values for the
very same term (which you cannot do with a single field). This makes
sense because other of the term meta features is to allow any term to
have any number of parents, and often is needed that the term be sorted
differently depending on the parent it's being viewed from.
A quick example: let's say you've got categories for "People with H" and
"People with S". You might feel that Homer Simpson belongs to both: as
"Homer Simpson" when listed from "People- H", and "Simpson, Homer" when
listed from "People-S". If shown alone or in a batch (like a tag cloud),
the category would be "Homer Simpson"; shown in the (special) category
widget, then would apply the "viewed from" stuff (the custom order,
name, and description also). You can see that working in my site, FWIW.
There are already plugins to add some kind of term metadata in the repo
(I think about three), so if you're interested just in this feature, you
can use some of them to add the table and modify the widgets by
yourself. But if you want that feature to be compatible/used with other
features altogether (and not only compatible with possible future
versions/implementations of the same feature/structure), you should
design that with the big picture in mind.
Please note that with the termmeta method you can also namespace the key
for the order: you can use my_plugin_term_order, instead of just
menu_order or term_order or whatever. A good namespacing (which is
*always* a good practice) would for certain avoid any compatibility
problems with other implementations of the same feature that you didn't
by yourself: they'd have another namespace.
More information about the wp-hackers