Turn WordPress into a CMS with Pods Framework

If someone mentions the term Content Management System, probably WordPress, Joomla, Drupal, and others come to mind. But the only content types supported by WordPress out of the box are pages and articles, which is fine for most websites, but what if you want more? Luckily you can use the Pods Framework; it’s a WordPress plugin which enables you to add custom content types and their management to your WordPress installation.

I’ll show you some of Pods Framework’s functionality by giving you a quick tutorial on how you we can use it to make a library site. The site will contain an overview page with all of the books we currently have, and when the user clicks on a book link he’ll see its details.

Adding Content Types

First you have to install the framework. Just use the plugin installer in your WordPress backend like you always do; the full name of the plugin is Pods CMS Framework.

After installation, click on the Pods menu item in the side menu. Like the description says, a pod is a named group of input fields, which means that it’s a custom content type with properties which you define. Click the “Add new pod” button and create a pod named “books”.

After you make the book pod, the screen changes to show its properties:

By default, our new pod already has the columns name and slug. In this example, we won’t need slug, so just click the red X to the left of it to delete it. The book does however need some more information, such as its publisher, description, genre, author, publication date, and the book cover. Let’s create them now.

At the right you’ll see the ‘Add Column’ section. Enter appropriate column names in the Machine Name field and use ‘Single Line Text’ for the Column Type, except for the publication date and description. The type for the publication date should be Date, and the description should be ‘Paragraph Text’. As for the cover, we can just store an URL string to the image.

Pages and Templates

Once the pod is configured, go back to the side Pods menu and click Add book.

Add a few of your favorite books as an example, providing the necessary information and saving your work.

To display our pages correctly, we’ll need to make a small theme modification. Go to the theme’s directory (I’m using Twentyeleven for this example) and create a new file named pods.php. The content should be:

<?php
/*
Template Name: Custom Pods template
*/

get_header();
?>
<div id="primary"> 
 <div style="width: 93%;" id="content" role="main">
  <article id="post-0" class="post page hentry">
   <?php pods_content(); ?>
  </article>
 </div>
</div>
<?php
get_sidebar();
get_footer();
?>

Be sure to include the Template Name comment at the top of the file. This way, WordPress will detect it as template file and name it the same way you named it.

Now for our visitors to see the book collection we need to create the listing page to show all the books which are currently in the database. Go to Pods’ Setup menu, then the Pages tab, and then click ‘Add new page’. Name it ‘books’.

You should now see a text field where you can enter the code you want for that page. You can include HTML, Javascript, CSS and PHP. Use the following:

<h1><b>Book List</b></h1>
<?php
$pods = new Pod('book');
$pods->findRecords('id DESC', 10);
while ($pods->fetchRecord()) {
    echo '<li><a href="/book/' . $pods->get_field('id') . '">' . $pods->get_field('name') . '</a></li>'; //Create a link to each different book
}
?>

Then, set the Page Template select to ‘Custom Pods Template’ and save your work.

In order to view the pages correctly, there’s one additional configuration change we need to make. Go to Settings > Permalinks, select ‘Custom Structure’, and in the text field type ‘/%postname%/’. Now you should be able to view the page you just created by going to yoursite.com/books.

We still need to create a page which displays the book information, so click Pods’ ‘Add new page’ button again and use the name ‘book/*’. The * is important because it is a wildcard in the URL, in our case the id of the book.

We can retrieve the first wildcard value (and in our case the only one) by with the pods_url_variable() function.

This is the code to use for our books/* page:

<?php
// store the book’s id into $bookId
$bookId = pods_url_variable(1);

// retrieves all book entries which fullfill the parameter requirement
$params = array('where'=>'t.id = '. $bookId);
$book = new Pod('book', $params);

// the pods is mostly a data class which contains multiple pod objects
while ($book->fetchRecord()) {
    // use get_field() to retrieve the value of a specific field
    echo '<h1>' . $book->get_field('name') . '</h1><br />';
    echo '<img src="' . $book->get_field('cover') . '" /><br />';
    echo 'Autor: ' . $book->get_field('autor') . '<br />';
    echo 'Publisher: ' . $book->get_field('publisher') . '<br />';
    echo 'Release date: ' . $book->get_field('release') . '<br />';
}
?>

Now we can easily manage our book collection and show it to the world. You can see that with the Pods Framework you can easily create a powerful website using WordPress. Actually, the possibilities are almost unlimited since with wildcards you can emulate a routing system that other frameworks might use.

For more information about the different Pod methods, you can visit the Pods Codex and ask for support in the Pods Forums.

Image via Fotolia

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • http://pods.io/ Scott Kingsley Clark

    Pods 2.0 lets you do even more, I suggest to your readers to check that out, it’s currently in beta but do out in a matter of weeks. It lets you create/extend WP object types like Post Types, Taxonomies, Media, Users, and Comments. Definitely worth a look at, maybe you can update your post to reference some of the cool stuff coming?

  • http://www.adrianmiu.ro Adrian Miu

    I think that for turning WordPress into a CMS it’s better to use a plugin for managing custom post types and custom fields than this. It achieves the same results while using WordPress’ underlying engine and look.

    • http://pods.io/ Scott Kingsley Clark

      That’s what Pods 2.0 is all about, my other comment hadn’t been approved by the time you replied, but hopefully you can check out what we’ve come up with. We’re also sponsored by Automattic as of this summer and have a lot of cool things planned for 2.x

  • http://www.udemy.com/php-for-code-phobes/ Ryan Kennedy

    This is fantastic, i was looking for nice clean way to deal with content types. Thanks!

  • salvatore fusto

    Hi,
    can pods content be generated from sever side language scuh coldfusion, or only from php?
    Regards

    • http://pods.io/ Scott Kingsley Clark

      Salvatore, we’re working on new API integration for XML-RPC and the JSON API plugin, look for it soon and you’ll be able to perform a variety of actions without needing PHP or even the server itself.

  • Sebastian Green

    Why would you use this plugin?

    You can achieve the exact same thing with custom post types and custom fields. It requires less code to output the data on the front end.

    To me this is just re-inventing the wheel, for no reason as its actually more complex.

    • http://pods.io/ Scott Kingsley Clark

      I can’t say we haven’t been asked that question before, I can turn around and ask the same question of you, why would you use WordPress? Surely you can achieve the same thing with custom PHP, but having an interface and a codebase can really streamline things across multiple projects. Beyond that, I think after reading this article you might not yet realize that with Pods 2.0 (not mentioned in this article) is coming out next Friday and since it covers WP objects (read some of my comments above) you can use any of the built in WordPress theming functions. Best of both worlds in my opinion :)

  • http://www.ans2ques.com Rafi

    Pods! yeah, that’s a great plugins ever, I will use it of next project.

  • Richard Meaden

    Been loving Pods – a great solution and made my job easier. I’m astonished at the lack of imagination from some of post comments. It’s certainly not more complex. Check it out! I’ve not used 2.0 yet as it’s just come out, but I’m keen to try out the enhancements and new features. I’m no PHP expert by any stretch, but Pods has helped me along and encouraged me to do more with my WordPress projects.

  • Robert Diaz

    I have been using the Custom Post Types plugin to create the custom post types, and the Advanced Custom Fields plugin to customize those new custom post types (as well as existing pages/posts). I find that to be a great solution that requires very little code to implement. Of course, programming knowledge is necessary when it comes to customizing and getting the most out of any plug-in. I’m curious to try out Pods and see how it compares. Thanks for introducing me to it!

  • http://www.smartcreative.ro CostyD

    Something similar is Magic Fields: http://magicfields.org/

  • Mike

    I have to agree with Rafi and Ryan – Pods is absolutely fantastic. The only thing it’s lacking right now is documentation for the new 2.0 version. I know they’re working on it and I can’t wait to dive into it once it’s available! For now I’m muddling through 2.0 as best I can. It just feels like it’s been incredibly well coded and with Automattic behind it now, I’m sure it’s only going to get better and better.

  • http://- Bilal

    PODS is one of the most powerful WordPress Plugins I have seen so far! Keep it up guys!

    Regards