Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

160 PART II • Designing and Developing WordPress Themes


◾ Separate various kinds of terms. With a specific taxonomy for person, companies, and
brands, you can create term clouds consisting of just persons, for example, and style each
kind of archive differently.
◾ Create your own post formats that fit your needs. The post format feature really is a
custom taxonomy given some special love within the core. There is nothing that stops
you from forgetting about the post formats and just creating your own taxonomy with the
same purpose, but tailored for your needs.

The possibilities might not be endless, but there surely are a lot of options in terms of organ-
izing and connecting the content thanks to custom taxonomies.

GET YOUR MIND WORKING
It goes without saying that being able to add new taxonomies, essentially new separate sets of
terms, can come in handy. Sites looking to work with data in almost database-style can
definitely put this capability to good use, as shown with previous suggestions, but it can also
be a different way to tackle the sorting of content. In particular, the addition of more taxono-
mies can make it possible to further push the categories to a design-driven feature within a
site. After all, tagging offers so much more focused control where it matters, and you get that
when you add your own taxonomies as well. You can have a taxonomy for design tagging
only, for example. The terms in this taxonomy would be used only by the theme, by adding
classes to the post article or perhaps the body tag. There’s no default support for this, but
it can be used nonetheless by adding it to the theme using a few snippets of code.

You can also imagine some taxonomies overlapping with custom fields because some usage of
this feature is all about organizing posts. Taxonomies are better suited for this by nature.
Taxonomies reach their full potential, however, when larger amounts of content need to be
controlled. Taxonomies are, after all, a sorting feature, and that means they work best when
there is actually something to sort.

At first, it can be a bit daunting to wrap your mind around the possibilities that custom
taxonomies offer. This feature can be put to good use, no doubt; several WordPress-powered
sites are already putting taxonomies to useful work. You, as an end user, may not see it, but
the developer may not have to write a bunch of plugins or strain the not-so-user-friendly
custom fields to achieve the content organizing and presentation needed. So don’t forget
about taxonomies; they might be your best bet for your project.

TAXONOMIES AND PORTABILITY
Custom taxonomies are great, and I’m sure that you already have a ton of ideas for how you
can use them. However, you need to remember that although you can create them from your
theme’s functions.php file, that part actually belongs in a plugin most of the time. The reason
for this is that you want to keep your custom taxonomies around when you switch themes, so
make sure that the taxonomy creation belongs in a plugin whenever possible, and let your
theme worry about the output in terms of template files.

You can read more about data portability in Chapter 8, “Plugins or functions.php?.”
Free download pdf