Creating book template files

WordPress needs to know how to display your new post type. You have to create a template for a single book, and one for the listing of books. Perform the following steps to do this:

  1. First, we'll make a book version of single.php. It must be named single-POST_TYPE_NAME.php, which in our case is single-book.php.
  1. Using page.php as our starting point (as it's already the closest to what we'd like our book page to look like), we're going to add the display of the custom field, book_author, and the featured image.
  2. So, let's start by taking our page.php file, making a copy of it, and renaming it single-book.php. Also, let's make a copy of content-page.php and call it content-book.php.
  3. Next, it's time to include all ...

Get WordPress 5 Complete - Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.