A Cozmoslabs Product
Documentation / Swift Templates / Create Single Templates for your Custom Post Type

Create Single Templates for your Custom Post Type

WCK Swift Templates makes it easy to create a Custom Post Type Single Template that will display the attached Custom Fields and Taxonomies.

You can achieve this without writing any PHP code, directly from the WordPress admin interface. The steps below will guide you on how to create a Custom Post Type Single Template using WCK Swift Templates.

Building the Custom Post Type, Custom Fields and Taxonomy

With WCK Swift Templates creating a Custom Post Type Single Template is done together with the creation of the Custom Post Type Archive Template, so the same steps apply.

For this tutorial we’ll follow the same example of using a Custom Post Type called Movies, created using WCK Custom Post Type Creator.

WordPress Creation Kit - Swift Templates - Movies

As you noticed, the “Movies” Custom Post Type has attached a Single Custom Meta Box called “Movie Information” with the following Custom Fields: Poster, Release Date, Director.

Below it there is a Repeater Custom Meta Box containing “Movie Actors” with the following Custom Fields: Name, Role, Picture.

The Custom Post Type Movies has also a Custom Taxonomy attached called “Genres” created using WCK Custom Taxonomy Creator to classify each movie easily.

Creating the Custom Post Type Single Template using Swift Templates

We want the “Movie” Custom Post Type Single Template to display all the Custom Fields and Custom Taxonomy information. Usually the default WordPress Custom Post Type Single Template only displays the Post Title and Content.

WCK Swift Templates offers an UI for building your own Custom Post Type Single Template with all the attached Custom Fields and Taxonomies.

We’ll create a new Swift Template and name it “Movie List”. Then we need to select a Custom Post Type that our Single (and Archive) Templates will be based on. From the dropdown select “Movies”.

WordPress Creation Kit - Swift Templates - Movie List

Then we’ll select a Query Argument. You have a lot of options here (as seen below) starting from Posts per Page, Order, Order By etc. to Tag or Category ID.

WordPress Creation Kit - Swift Templates - Post Per Page

We’ll choose Posts Per Page and use the Default Value of 10.

IMPORTANT: After this step make sure to “Publish” your Swift Template so it can generate all the variables needed at the next step.

Moving forward we’ll get to the Swift Template tab were we can start building the Archive and Single Template. In the right side you will see a list of all the available variables for the selected Custom Post Type “Movies”.

WordPress Creation Kit - Swift Templates - Single Template

For the “Movies” Custom Post Type Single Template we want to display the following information:

  1. Title
  2. Description
  3. Genre
  4. Movie Information
  5. All Movie Actors information

We can start building the Custom Post Type Single Template by selecting the variables we need from the right side and adding them to the left side editor.

Note: To properly display the WYSIWYG Editor Field used in the Swift Template, add the variable with 3 curly braces (3 mustaches): {{{ custom_field }}}

And we can also add a little bit of HTML for a basic layout.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<img src="{{movieinfo_poster}}" class="alignright"/>
{{{post_content}}}
<strong>Release date</strong>: {{movieinfo_release-date}}<br/>
<strong>Director</strong>: {{movieinfo_director}}<br/>
<strong>Genre</strong>: <br/>
{{#taxonomy_genre}}
  {{term_name}} 
{{/taxonomy_genre}}
<h4>Actors:</h4>
<ul>
{{#movieactors}}
    <li><img src="{{picture}}" class="alignleft" />
    Name: {{name}}<br/ >
    Role: {{role}}
    </li>
{{/movieactors}}
</ul>

Make sure to mark the checkbox below the Single Template Editor to use it on all posts for the selected Custom Post Type.

WordPress Creation Kit - Swift Templates - Single Template Structure

Then “Update” the newly created Swift Template and you’re all set.

Now if you have a look at the Movie Single Page it will display all the attached Custom Fields and Taxonomy information.

WordPress Creation Kit - Swift Templates - Front End Single Movie

Feel free to move forward and style your new Movie Single Page in any way you desire.

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket