Yesterday I received an email contains the announcement from Scott Kingsley Clark; the lead developer of Pods Framework plugin about the plan of Pods 2.0 release today on my local time September 22, 2012. Yeah, it’s been a long time waiting for Pods 2.0, and today it was really here! So excited, eh?
After trying to play with it, then here’s step by step how to display Pods Item using Pods Page and Pods Template using the new method. This is the simplest example to give you the idea how it works as well as Pods 1.x. Actually, there are some big differences between Pods 1.x. So, I suggest you to install Pods 2.0 on your computer in localhost instead of on the production server in order to play with it.
In the following example, I will show you how to add a new Pods content; which has its own table; named countries. Of course, you can enhance it so it will suit with your needs.
Activate Pods and Setup New Pods
- First of all, download Pods 2.0 plugin by clicking here, extract it to your /wp-content/plugins/ sub-folder of your WordPress installation, and then activate it.
- From your WordPress Admin menu, go to Pods Admin -> Setup.
- You will see an Add New Pods page, and you are in the first step: 1. Create or Extend. Just choose/click on the Create New option.
- From the Content Type directive, choose Advanced Content Type (separate from WP, blank slate, in its own table).
- In the Plural Label, type: Countries.
- Click on the Advanced + link, and make sure in the Identifier directive is not blank. The value should be countries.
- In Singular Label, type: Country, and then click on Next button on the right bottom of the page.
- Now you should see an Edit Pod: countries page appears. You will see there are five fields have been created by Pods by default. They are: Name, Date Created, Date Modified, Author, and Permalink. Now we will add a new field named Country ID. Follow the next step below.
- Click on the Add Field button, and then in Basic tab, click on Label directive, and type: Country ID
- Press Tab button in your computer keyboard, then in the Name directive should be filled in with the value of country_id. Make sure this directive is not blank, otherwise you cannot procede to the next step.
- In the Options directive, make sure you have given the checked marks at Required and Unique items, and leave the others at this moment, then click on Add Field button.
- Now we will configure another settings in order to make this Countries Pod is displayed in your WordPress Admin menu. Click on the Advanced Options link in the below of Manage Fields section, and then in the Label tab, make sure in the Label directive has been filled in with Countries and in the Singular Label directive has been already filled in with Country.
- Click on the Pod Options tab, and in the Detail Page URL directive, type: countries/{@permalink}, give checked mark at the Show in Menu item, and then in the Title Field, make sure has been selected with Name.
- Click on the Save Pod button in the top right of the page in order to save the changes to your database, and make sure you have already seen a new menu appears below the Comments; named Countries.
Add New Records
- Hover your mouse to the Countries menu in WordPress Admin menu, and then click on Add New sub-menu.
-
Now let’s add some new records, and in this example, will add seven records.
They are:
- Indonesia (Name: Indonesia, Permalink: indonesia, Country ID: id),
- Australia (Name: Australia, Permalink: australia, Country ID: au),
- United States of America (Name: United States of America, Permalink: united-states-of-america, Country ID: us),
- Singapore (Name: Singapore, Permalink: singapore, Country ID: sg),
- Germany (Name: Germany, Permalink: germany, Country ID: de),
- Italy (Name: Italy, Permalink: italy, Country ID: it), and
- Canada (Name: Canada, Permalink: canada, Country ID: ca). - Check the records, by clicking on All under Countries menu in the sidebar of WordPress Admin.
Activate and Setup: Pods Template and Pods Pages
- In Pods 2.0, Pods Page and Pods Template are located under Pods Admin -> Components sub-menu. Click on the sub-menu, and then activate Templates and Pages components.
- Go to Pods Admin -> Templates, and then click on Add New button at the top of page.
-
Now you should see an Add New Pod Template page appears. Let’s create a Pods Template for displaying the detail of Pods Item. To do this, enter the template name: country_detail, and copy the following code to the Content directive:
and then click on Publish button at the right side of page.
-
Let’s add the Pods Template for displaying the list of Pods item. To do this, click again on Add New button, and then enter the template name: country_list, and copy the following code to the Content directive:
and then click on Publish button at the right side of page.
- Go to Pods Admin -> Pages, and then click on Add New button.
-
You will see an Add New Pod Page page appears. Now we will add a new Pods Page that contains the list of the Pods items and this page is related to its URL structure. In addition, we will also add the pagination to this List page. To do this, at the first textbox, enter the URL: countries, and in Page Title directive, type: Countries List, and then in the Content directive, type the following code:
<?php
// Get 3 records per page, ordered by name ascending,
$params = array( 'orderby' => 'name ASC', 'limit' => 3 );
// Maps to the new find method
$pod_countries = pods( 'countries', $params );
// Display it to the template
echo $pod_countries->find( $params )->template( 'country_list' );
// Display the pagination
echo $pod_countries->pagination();
?>afterwards, click on the Publish button.
-
Now we will add a new Pods Page for displaying the detail of Pods item, and it is related to its URL structure. To do this click again on Add New button, and then enter the URL: countries/*, and in Page Title, type: Country Detail, and then and copy the following code to the Content directive:
<?php
// Get the latest variable from Pods URL
$id = pods_url_variable('last');
// Define the params to find the Pods Item based on the $id
$params = array( 'where' => 'permalink = "'.$id.'"' );
// Display it by using Pods Template
echo pods( 'countries' )->find( $params )->template( 'country_detail' );
?>afterwards, click on Publish button at the right side of page.
Check the Results!
-
That’s all. Now let’s have a look the result. Type in the URL of your browser the address (assume my WordPress localhost installation is: http://localhost/wppods/), so it will look like this: http://localhost/wppods/countries/. You should see the list of the three records of the countries appear in the page:
Australia
Canada
Germany
1 2 3 Next › Last »whereas each of them has the link to its detail Pods item. As you can see, the pagination will be displayed also at the bottom of that page. You can navigate to the next or previous page.
-
Click on one of the records (for example: Australia), then in the next page you will see the detail of the country which has the URL http://localhost/wppods/countries/australia.
The page will show you the content just like this:Country Name: Australia
Country ID: au
Permalink: australia
This is the first comment, since I re-installed my blog.
Ah, finally it’s alive! I’ve been checking on your blog last several days as it turns out that you got the best tutorial on Pods 2.0 and everyone’s referring to you.
Can you give me a link to usage reference of the parameters, that are applicable to find() ?
Thank you, Vladimir Vassilev.
Sure. Please check this out: http://podsframework.org/docs/find/
Ah, great, that answers my question perfectly! I wonder how I did I miss it till now… thanks a lot!
Hi, im very new to WordPress, but used other CMS’s, just having a play around with it for work and wanted to get my heard around customizing content. To keep things short, I followed the tutorial twice but was getting page not founds when trying to view “http://localhost/testwpsite/countries/”
Running windows/EasyPHP/Wordpress 3.4.2 and Pods 2.0.4.1
I have tried it on a vanilla install, is there anything else I have to do, or should try?
Cheer
Aaron
Go to your WordPress Admin Panel (wp-admin) -> Settings -> Permalinks, and then make sure you have chosen Day and name option, and then click on Save Changes button. Also make sure rewrite_module is enabled in your Apache server.
Brilliant Thanks! That worked, I had to rebuild the pod pages after I change the permalink setting, but I think I could have cleared a cache or something to get around it.
Cheers!
First off, thanks so much for explaining Pods here with this real-life example. It really helped me what to choose Pods and start learning how to use it.
Referring to #7 in your post above, how could I find the Pods Item based on more than one value? I have a puppies Pod and would like to show only the males that are not sold (for search reasons).
For
I’m successfully using:
(true is male, false is female)
I would also like to add:
(true is available, false is sold)
I tried this without success:
How to do it?
Ahh, I figured it out – too many quotation marks:
$params = array( 'where' => 'gender = true && available = true' );
?>
Thanks anyway!
For step #6, under “Activate and Setup: Pods Template and Pods Pages”, I believe that the
part of your code is redundant.
According to this documentation, the find function is automatically run when an array is provided as the second argument to the pods() function call.
Please correct me if I’m wrong.
Thanks for the great tutorial!
Hi Mike,
You are right. However, I was including $params in order for consistency in writing code; either for displaying list of Pods item (countries/) or displaying detail of Pods item (countries/*).
As you can see, if you implement the same technique for “countries/*” Pods page, it will not work. In addition, I referred to Differences between 1.x and 2.0 when I was playing with it.
Here is the quote of code I copied from that article regarding it:
echo pods( 'mypod' )->find( $params )->template( 'template/name' );
Sorry, I wish I could edit my previous comment to add this. Just for clarity’s sake.. so instead of:
echo $pod_countries->find( $params )->template( 'country_list' );
you should be able to have
echo $pod_countries->template( 'country_list' );
Roger that. Both of them are working properly only for list of Pods item, but not for detail of Pods item.
As I mentioned in my previous reply to you, I prefer always including $params for consistency in writing code; either for displaying list of Pods item (countries/) or displaying detail of Pods item (countries/*), since your suggestion code will not work for detail of Pods item.
Thanks for your reply Masino. Can you help me understand why that same shortened code doesn’t work for displaying the detail of Pods items? I’m not quite wrapping my head around it.
I actually just tested it and it does work as expected. Here is the code I’m using. Please let me know if you get the same functionality:
Pod Page: countries
$params = array( 'orderby' => 'name ASC', 'limit' => 3 );
// Maps to the new find method
$pod_countries = pods( 'countries', $params );
// Display it to the template
echo $pod_countries->template( 'country_list' );
// Display the pagination
echo $pod_countries->pagination();
?>
Pod Page: countries/*
$id = pods_url_variable('last');
// Define the params to find the Pods Item based on the $id
$params = array( 'where' => 'permalink = "'.$id.'"' );
// Display it by using Pods Template
echo pods( 'countries', $params )->template( 'country_detail' );
?>
By the way, what tags does your comment form support if I want to mark a code block as such?
Thanks again!
Yeah, there are several ways actually, but as you can see, I would rather using my way only just for consistency in writing the code (again).
Regarding the tags code, please refer to CodeColorer plugin.
Thanks for great post. Now I trying to solve this problem. I am making the iPad Application catalog. I successfully defined new pod and template. Then I wrote new WP Page Template with php code for listing of the applications (pods). Each pod have set of the check boxes (YES/NO) for making taxonomy. But how can I filter the pods? For example the apps for grammar school, apps for primary education etc.
In pods() function is parametr where, but there is not any taxonomy atribute in wp_post table. Many thanks for help.
I am not exactly sure whether I can answer your question, but I suggest you to read this documentation regarding the Taxonomy. In my humble opinion, most of features in Pods have been handled by and saved as Post types.
Great Article, thanks.
I fail to show pagination. The function returns a blank string. It appears to happen in the function do_hook which is part of the pagination return value. Is there some parameter I am missing. I see the list of 3 test records but the pagination line is missing.
I would appreciate any suggestions.
Please try not to use do_hook.
I’m getting a database error on the Country Detail page saying:
Response: Unknown column ‘permalink’ in ‘where clause’
The issue being caused by this line of code in the countries/* page:
$params = array( 'where' => 'permalink = "'.$id.'"' );
Any ideas on what the issue is?
It’s weird, since the permalink is a field that automatically generated when you create a new pod. Have you done all steps above?
All accept step 13 in Activate Pods and Setup New Pods:
Click on the Pod Options tab, and in the Detail Page URL directive, type: countries/{@permalink}, give checked mark at the Show in Menu item, and then in the Title Field, make sure has been selected with Name.
I’m thinking Pods latest version has changed since the tutorial was made as I can’t see the “Detail Page URL” field anywhere or a checkbox for “Show in Menu”..? Basically this whole step is a little unclear to me..
I think you have to make sure to choose the Advanced Content Type in step 4 or you don’t get those options.
Aye, you don’t get those options without choosing Advanced Content Type, but unfortunately, you can’t associate taxonomies with Advanced Content Types, only with posts & pages. Jaime’s reply right below this one though fixes the problem:
http://www.openscriptsolution.com/cms/wordpress/pods-2-0-how-to-display-pods-item-using-pods-page-and-pods-template/#comment-4193
You can solve it if you change in the query ‘permalink’ by ‘post_name’.
Something like that:
At least it works for me.
That worked for me as well. Thanks!
When I follow these steps, in steps 6 and 7, I don’t have textareas labelled “Content” — I only have “Page Code” and “Page Precode”
If I put the output in “Page Code,” nothing appears on my pages.
If I put the output in “Page Precode,” the output appears (as expected) before the tag.
Do I need to add something to a .php file like page.php to get my content to appear?
Blech, the content wasn’t appearing because I actually still had an old, incorrect pods.php file in my themes folder from an earlier attempt. Deleted this file and content appears as expected.
Just as a heads-up though, there is no “Content” textarea, just one called “Page Code”
What version are you running?
I’m having real difficulty getting the pods pages to work. I managed to display a template in my page.php manually, but going to ‘/countries’ or to ‘/countries/australia’ will show either:
A page with no content – if I’ve not not selected a page template in the pods page admin.
Or the following error:
Notice: Use WP Page Templates or hook into the pods_content filter instead of using Pod Page PHP code has been deprecated since Pods version 2.1.0 with no alternative available. in C:\Websites\xxxxxx\httpdocs\wp-content\plugins\pods\functions.php on line 260
If I’ve selected ‘Page’ as my page template.
I’m running pods 2.2 – can you help?
Thanks for the tutorial! It saved my website!
This paginates the list of pod records over however many pages are required based on the limit (per page). How do you Paginate the pod records themselves, as in either ‘side’ of Canada, Previous or Next being Australia or Germany respectively in this example?
Under “Activate Pods and Setup New Pods” step 13 says to type in a value into the “Detail Page URL” field. using Pods v2.3.1 I don’t see such a field. How would I go about setting this up in this version? Thanks.
This tutorial seems outdated or at least not compatible with the current version of Pods. Would be great to see an update for the same.
Thank you,
This is awesome, but I have a really long list of countries in a .CSV file… how do I add that data so I can put them into the correct fields?