Example Template Tag Usage

Examples of Pods Templates using a mixture of tags

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 [if] 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}
                [if cover_images]
                    <ul>
                        [each cover_images]
                            <li class"cover-image [if field="_position" value="1"]first-cover[/if]">
                                {@_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 Books

[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]
    </tbody>
</table>
[/after]

Other Helpful Documentation on Template Tags

BEFORE and AFTER

Provides the ability to run a opening block in your template that will be output BEFORE and AFTER the loop.

EACH Loop Tag

Provides easy looping through related entries (from relationship fields), taxonomies and media upload fields within Pods Templates.

IF/ELSE Conditional Tag

Provides simple conditional logic for your Pods Templates

ONCE Template Tag

DO NOT USE. This Tag has been deprecated. Use CSS with nth positioning :first or the if shortcode if you need this functionality.