Your Views can display all standard WordPress fields (like title and body), custom fields and also Content Templates.

Content templates allow you to create complex meta HTML – mixing Toolset shortcodes and HTML, and insert it as a block several times in a single View, or across different Views in your site. A simple way to re-use code in your site.

We’ve used this technique to build the Service grid in our Views Tutorial – if you haven’t already, then watch the Services grid Views tutorial video to see eactly how.

Re-using code on your site

Let’s take an example where we are using the post date frequently in our site’s Views. But instead of just the date, we want to display the formatted date and time, and add a little markup to our site. This is the HTML structure we are going to be using:

<span class="post-date-time">[wpv-post-date] at [wpv-post-date format="g:h a"]</span>

You can create a Content Template directly from your view or from the Toolset->Content Templatess menu.

Adding a Content Template from within your View

In the View editor GUI, scroll down to the Loop Output editor, place your cursor where you want your view inserted in the loop, and click on the Content Template button.

 

Add content template to View
Add content template to View

 

This will open the Add new Content Template dialog. You can Connect an already existing Content template to this View, or, as we’ll do in this case, Create a new Content Template for this View and give it a name.

 

Add content template dialog
Add content template dialog

 

You’ll see that the shortcode for your template has been inserted into your View.

Insert content template
[wpv-post-body view_template="Post date time"]

and if you scroll down a little, you’ll see that a new Content template edit window has been created for the template.

 

Templates for this View
Templates for this View

 

Any shortcode or HTML that you add to your Content Template, will be displayed wherever the Content Template shortcode is inserted.

If you want to edit you Content Template later, you can either return to the View, and open the template there. Or go to Toolset -> Content Templates and edit your template directly.

Other ways of adding your Content Template

You can add an existing Content Template directly from the View Loop Wizard.

 

Insert content template from Loop wizard
Insert content template from Loop wizard