0

The Problem: My personal blog resides at example.com, and I want to create a bookshelf where I share all the books I read or plan to read. I could do this in two ways:

  1. Create a category called "Books" to display the latest books I added (like archive).

    Create a custom taxonomy "Subject" to classify books.

    Use custom template files category-books.php and taxonomy-subject.php, and use in_category( 'books' ) in single.php to customize the look (so that it looks more like a bookshelf).

    The permalink structure of my blog is already like this: /%category%/%postname%/ and the category base is stripped. Therefore, the URLs of the Books archive and the book (post) would look like: http://example.com/books/ and http://example.com/books/book-name/, respectively.

    Use Advanced Custom Fields plugin to display some custom meta boxes conditionally in the edit page, i.e. only when "Books" category is checked.

  2. Create a custom post type called "Books" with 'rewrite' => array('slug' => 'books'). Therefore, the URLs of the Books archive and the book (post) would look like: http://example.com/books/ and http://example.com/books/book-name/, respectively.

    Create a custom taxonomy "Subject" to classify books.

    Use custom template files archive-books.php, single-books.php, and taxonomy-subject.php to customize the look (so that it looks more like a bookshelf).

    Use Advanced Custom Fields plugin to display some custom meta boxes in the edit page for the custom post type - "Books".

Which of the two methods is the better way to accomplish what I am after? (I mean the way it's meant to be done.)

I am still confused as to whether or not custom post types are meant for this purpose; even after reading these:

1 Answer 1

3

I will start from the end.

Post Format is a taxonomy with only 9 terms. The only reason they exists is to set a sort of standard for theme developers. Once the terms are only 9, and the term names cannot be changed by the users, (the users can select them only via a radio button when create posts), theme developers can create template files like "taxonomy-post_format-gallery.php" being sure that this template will be used for archive of posts with 'gallery' post format. Also can use has_post_format function with a specific term: this cannot be done with standard categories or custom taxonomy, because the terms are choosen by users.

E.g. if I create a theme and put somewhere a conditional if ( has_category('foo') ) and my theme is used by other people, I can't be sure that the users of my theme will use the category 'foo' for their posts, on the countrary, I can use the condional if ( has_post_format('gallery') ) because the format 'gallery' is standard.

In short, post format are a sort of categories with standard term names, that exist to help theme developers (expecially ones that sell or distribuite themes) to stylize posts depending on their content in a way that is shared among the thousands of themes that exist for WP: even if a user switch theme, the post will be stylized in right way if both themes support post format.

It's important to note that post format can be assigned only to standard posts, not to CPT.

In your case, the book is not one of the 9 terms, so you can exlude post format.

Now, going to the choose custom taxonomies vs custom post types.

First of all, you shouldn't decide the structure of your site based on url, on the countrary, you should adjust your urls to "mirror" as close as possible the site structure.

Said that, you should think what are taxonomies and what are post types.

Posts, in general, are information containers. The post types are intended to organize this informations into types. Taxonomies can be used to group togheter informations of same type or different types that share a characteristic.

In general one information can be only of one type but can have different characteristics: the type in WordPress should be handled via post types, the characteristics via taxonomies.

In your case, book is a type of information. That have some characteristic. One is the subject, that correctly you want to handle via taxonomy, in fact a book can have more that one subject, but cannot be a Book and at the same time a News that is another type of information.

In conclusion, you should use a CPT for Book, and group them into subject using a taxonomy.

Regarding the urls I think that the standard example.com/books/ for book archive and example.com/books/a-book-name for the single book can be optimal, unless you have particular needs.

2
  • Thanks for taking the time to write an explanative answer. :)
    – its_me
    Oct 9, 2013 at 20:12
  • You are welcome :) @its_me
    – gmazzap
    Oct 9, 2013 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.