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

(avery) #1

CHAPTER 6 • Advanced Theme Usage 133


RULE #1: STYLE BY CATEGORY, SORT BY TAG,


AND TUNE WITH POST FORMATS


Categories are great for rough sorting, such as a category for Music and another for Books,
but they should never be too niche. Tags, on the other hand, can be as precise as needed,
which means that a book review may belong to the category Books and have tags that identify
the book’s author, genre, title, publishing house, and so on. The purpose of this isn’t just
nomenclature; there are technical reasons behind the decision. First, it’s easy to create custom
looks for category listings using the category.php and even category-X.php (X is the ID, or the
category slug) template files. These can let you list one kind of content in one way and a
second kind in another.


Tags, on the other hand, are niched in themselves and should be viewed partly as search
keywords that get grouped together and partly as descriptions of the content. They can be
useful as both, especially when you want to collect all those J. K. Rowling book reviews
without having to force a traditional (and not so exact) search. By carefully considering how
you set up categories and tags and how they relate to each other, you can achieve a great deal.


Need more control? Sometimes the default category and tag taxonomies won’t cut it. That’s
when you create your own taxonomies to provide even more specificity. Custom taxonomies
are great because although you can use them for additional organization, much like tags and
categories, you can also keep them completely hidden from the visitor. Using a custom
taxonomy to add more control over post styling is great, for example.


Need even more? Post formats give you additional control over posts and how they can be
styled and managed. In typical blog fashion, this is often a more suitable solution than using
categories for styling, so weigh these against each other.


RULE #2: CAREFULLY CONSIDER CUSTOM FIELDS


Custom fields are very useful. They can store data as well as images, and they can fill in the
blanks when you need more than just a title, a slug, the content, and an excerpt or when you
want to sidestep the categories and tags. That’s great. They are not, however, very user-friendly,
as I’ve already argued, and that means you need to be wary. A lot of funky WordPress-powered
sites need to rely heavily on custom fields, but in such cases, you need to educate the people
running them. A plugin, which can do the same thing but just not show it, may be a better idea.


Post metadata can be quite useful, however, and by building your own boxes for managing
said data, you can make it a lot more user-friendly than the default custom fields interface. If
you need custom field functionality, you should definitely build your own metaboxes and
tailor them to your needs — or consider using plugins that do this for you. Which plugins
work for you depends on your needs obviously, but a lot of people swear by Advanced Custom
Fields (www.advancedcustomfields.com), so at least that one is worth checking out.

Free download pdf