This post was written by Markus Stefanko

How to create a Pods page

A very basic tutorial on how to structure your pods project and on how to start with Pods. It can be quite confusing at times to find proper and current material online about it, so let’s keep it simple.

This tutorial is written for the currently latest Pods version 2.3

What do we want to achieve?

We want our WordPress to respond to any urls containing cars – e.g. myblog.com/cars/bentley in them to respond with the equivalent Advanced Content Type Pods items.

Note : We don’t really need Pods Pages for Custom Post Type Pods, or Custom Taxonomy Pods. Those are handled already by WordPress, and you simply need to adjust the relevant existing templates like e.g. single.php or taxonomy.php and pull the info there as you’d do with regular Posts, Pages or Taxonomies; Pods Pages are in 99% of the cases only useful for Advanced Content Type Pods

Also make sure to check out the excellent tutorials over at the official pods page, on what ACTs actually are, and what their use cases would be best for.

The setup

It’s quite easy – simply go to your WordPress administration area, in the left navigation bar in the bottom you’ll find Pods Admin and right below it Components. Get into there, and make sure to enable the Pages component.

You will see now a new point under Pods Admin : - Pages.

Create the Custom Page Template the Pods Page should call

Go into your active theme’s current folder, which could be for example /wp-content/themes/mytheme and create a new PHP file – let’s call it car-detail.php. This will be our code template for the car page, so make sure to name it in the first few lines like the following :

<?php
/*
Template Name: Car detail page
*/

The Template Name part has to be the first thing in the file, and shouldn’t be moved. That way WordPress knows that you want to use this file as a Custom Page Template. To read more about WordPress templates, check out Page Templates in the WordPress Codex

Then afterwards we can start adding our code. For example we can use in this case the pods_v function to tell us the last part of the URL, if divided by slashes; so the last part of this URL : mypage.com/cars/bentley would be bentley.

// Our code starts here...
echo "This is a car detail page for : " . pods_v( 'last', 'url' );

Now save the file.

Create a Pods Page in the WordPress Admin

Now it’s time to create a Pods page which will call this file. In order to do so, we’re going in the WordPress Administration to Pods Admin : - Pages and click the Add New button.

You will see in the top, that the first input item shows ‘Enter URL here’ – that’s where we enter : cars/* – this will call this specific pods page whenever a url matches cars/ + anything afterwards.

Now the final step is to assign the proper Page Template. Usually the 5th item on the page is called Page Template, and in the selection list you should be able to select our freshly created Car detail page.

Press the Publish button, and we’re done.

Test it

Now when you navigate over to yourblog.com/cars/bentley you should see a white page with the text :
This is a car detail page for : bentley.

Done!

Next steps

The page itself looks quite empty, so you might want to add a get_header(); above and get_footer(); below your code, and generally do a few more styling parts as from your other Theme Template pages. Take a look in page.php and single.php for a few pointers on what’s possible.

To start working with an actual Pod, you will want to start loading the Pod based on the url item, like so :

<?php
/*
Template Name: Car detail page
*/

get_header();

$car = pods('car', pods_v( 'last', 'url' ));

echo "This car's name is  : ".$car->field("name")."<br />";

get_footer();

This way you can now simply edit your Pods pages without entering the WordPress Administration. Also you can edit them with your code editor – Sublime Text being our favourite here. And you can keep track of code changes now with a version control system, like Git; and work in teams on the code itself!

Enjoy playing around with Pods!

by Markus Stefanko