If you read a lot, or just some even, and want to share your insights and opinions with others, a great way is to add a custom post type on your website. A custom post type is essentially the exact same thing as the default ‘Post’ in WordPress. Coding or using plugins will enable you to create your very own post type, like the one I created called ‘Books’.
For this post I’ll use the Pods Plugin to set up the custom post types and add templates for displaying on the frontend. The process might be the same or very similar with other plugins. Other than Pods, no additional plugin is needed.
I have previously written about how to set up Pods plugin on WordPress here.
The finished result looks something like this:
Book Reviews: The Parts
My goal was to create a post type that would display well on the frontend with custom categories for genres, and another for authors. In this case I didn’t bother setting up tags since I think genres do the trick.
The project will thus consist of 3 custom post- and taxonomies:
- Book Review, the custom post type
- Authors, the custom, hierarchical taxonomy for listing the authors
- Genres, the custom, hierarchical taxonomy for listing the genres
Setting up Book Review as custom post type
The main custom post type have 15 custom fields, which are inputs that you can call in different places. For example, one field is called ‘book_title’ and contains the title of the book, similar to ‘book_subtitle’. This enables you to call the different fields in different places, perhaps if you want to display only the main title in the feed and the whole title on the single page, as shown here. The other fields I use are:
- Title (plain text) – The main title of the book
- Subtitle (plain text) – The subtitle of the bok
- Author (plain text) – A plain text field for the author’s name
- Series (plain text) – The name of the series the book’s a part of, if any
- Series-no (plain number) – The number of the book in the series
- Quote (plain text) – A short quote from, or about the book that might peak the reader’s interest
- Rating (plain number) – My rating, number 1-5
- Language (plain text) – The language of the book
- Pages (plain number) – Number of pages in the book
- Publisher (plain text) – The publisher
- Published (date) – Date of publish
- ISBN (plain number) – ISBN number
- URL (website) – Link to where the reader can purchase or read more about the book
- Content (WYSIWYG – Visual Editor) – Summary of the book
- Review (WYSIWYG – Visual Editor) – Review of the book
I’ve chosen to divide the content and review into different fields if I would want to display one or the other anywhere. There’s no real reason other than that and if you prefer, go with just one field for summary+review.
Advanced Options
Under ‘Supports’ I’ve enabled the following:
- Title
- Featured image
- Excerpt
- Quick edit
I’ve disabled the Gutenberg ‘Editor’ since I’ve had trouble using it together with custom post types and found it better to just add what fields I need in the CPT directly.
I do, however find the Featured image and Excerpt very useful to use in Queries and post lists! Quick edit is always nice to have, too.
Setting up author taxonomy
This is pretty straight forward, I wanted to create the possibility to have a dedicated page for each author, should I want to add a bio, website, profile picture, or whatever else. I thought a category would do the trick, with all the authors as parent-level categories. I could then add the book series as a sub-category for each author to be able to better sort and display the books and series later on as I add more books for each author. For now, though, the author custom taxonomy consist of two custom fields:
- Bio – A WYSIWYG for creating a nice-looking bio on each author
- Website – Just a url field to be able to link to the authors website
Setting up genres taxonomy
Just like the author taxonomy, the genre one is very simple and straight forward. It doesn’t even have additional fields, just a flat taxonomy. This is obviously to be able to create branches of genres as I add books, making it easier to find certain books.
Displaying Book Reviews on the Frontend
Now, we’re basically ready to get writing book reivews! However, we still need to display them properly on the frontend.
Create a Front Page Feed
For the purpose of displaying the book review as a feed on the front page, simply do the same as if you where about to create a normal WordPress post feed. I use the full site block editor for this.
Create a ‘Single Book Review’ template with Pods
My goal here was to have a nice looking single post page for the books. I want to highlight the book cover on the left side while listing the important information about the book on the right side. Then below, a summary of the book and below that the actual review. Very simple.
The main problem I ran into was to set up the dynamic links in the meta fields next to the image.
Displaying the name of the author while linking to the author category
Since I don’t do too much coding myself, I had to ask ChatGPT who, after quite a few back and forth came up with a code that does just that!
In this code, WP gets the information about the author and whether the author created any book series that this current book is a part of. It then outputs the information in a link that directs the viewer to the author’s page, if they click it.
Simple and effective!
<p> <?php $authors = get_the_terms(get_the_ID(), '[author]'); if ($authors && !is_wp_error($authors)) { echo '<span>Author: '; $author_links = array(); foreach ($authors as $author) { // Check if the term is a parent term if ($author->parent == 0) { $author_links[] = '<a href="' . esc_url(get_term_link($author)) . '">' . esc_html($author->name) . '</a>'; } } echo implode(', ', $author_links); echo '</span>'; } ?> <br> <?php $authors = get_the_terms(get_the_ID(), 'author'); if ($authors && !is_wp_error($authors)) { $series_links = array(); foreach ($authors as $author) { // Check if the term is a child term if ($author->parent != 0) { $series_links[] = '<a href="' . esc_url(get_term_link($author)) . '">' . esc_html($author->name) . '</a>'; } } // Check if there are series links to display if (!empty($series_links)) { echo '<span>Series: '; echo implode(', ', $series_links); echo '</span>'; } } ?> </p>
This is pretty much how my book review custom post type works, please do give me a shout if you have further questions or comments!
Leave a Reply