Books & Author List

This template is for a custom post type called “author” with a field called “books” that is a related to the custom post type “book”. It uses a conditional test to check if the author has any books, and if it does not it outputs the message “Author has no books uploaded.”. If the author does have books it outputs information from each of the related books, starting with the post title. Then it loops through the field “cover_images”, which is in the “book” custom post type. Inside of the loop, the [once] block is used to add an additional class to the first item only. If this template itself is looped the wrapping container.book-wrap will contain all items and not be repeated.

[before]<div class"book-wrap">[/before]
    [if books]
        <h5>Books</h5>
        <ul>
            [each books]
            <li>{@post_title}<li>
            [if cover_images]
                <ul>
                    [each cover_images]
                    <li class"cover-image">{@_img.thumbnail}</li>
                    [/each]
                </ul>
            [else]
                <p class"no-images">No Images for this book</p>
            [/if]
            </li>
            [/each]
        </ul>
    [else]
        <p>Author has no books uploaded.</p>
    [/if]
[after]</div><!--.book-wrap-->[/after]

Table of Related Items

[before]
<table>
   <thead>
      <tr>
        <th>Title</th>
        <th>Genre</th>
        <th>Year Published</th>
        <th>Link to Book</th>
      </tr>
    </thead>
    <tbody>
[/before]
[if related_books]
   [each related_books]
      <tr>
         <td>{@post_title}</td>
         <td>{@genre}</td>
         <td>{@year_published}</td>
         <td><a href="{@permalink,esc_url}" class="button">Learn More</a></td>
      </tr>
    [/each]
[else]
    <tr>
       <td colspan="4">No books found</td>
    </tr>
[/if]
[after]
    </body>
</table>
[/after]