The Last of the Pods Basics: Pagination and Sorting

The Series on Pods has been quite a success so far. I’ve had some back and forth with lots of new people who were itching to give Pods a try, and the series has been quite a bit of help to newcomers. I’m super happy about that, and I’d like to close out the initial push on the series with what I’ll call The Last of the Pods Basics. That is to say, I’d like to go over the last few bits that will really get you up and running with Pods in such a way that you can do even more with both your data as well as your user experience.

As a quick recap, if you haven’t read the first five articles in The Series, you will probably find this article a bit confusing. That said, please make sure you’ve read: An Overview of and Introduction to Pods CMS for WordPress, Pods Basics: Installation and Setup, Pods Basics: Pulling Pods Data to your Theme, Pods UI: The Latest and Greatest Addition to Pods, and How to use Pick Columns (Relationships) in Pods. Being up to speed is essential with this article, as it’s going to build on the system we’ve put in place using the previously published articles. You won’t need to recreate the structure set up in the earlier walk throughs, but knowing the existing implementation will help these instructions remain clear.

Paginated content in Pods

Pods comes with pagination built right in, it’s just a matter of getting it to work the way you want. We’ll begin by flooding the Team Pod we set up previously with a large group of entries. In addition to the Pod setup, I also added Pods UI to help manage the content.

Our new Team listing

If we were to check out our Team page now, we’d see that the listing has been limited to the default 15 records:

Team listing

Also by default, Pods doesn’t include any sort of warning that content wasn’t listed. It shouldn’t do that, because Pods does what you tell it to do. You have a few options here. The first would be to change the way we pull the original data. As it stands, we’re using:

<?php
  $team = new Pod('team');
  $team->findRecords('name ASC');
?>

As it turns out, findRecords has more parameters to work with, one of which is the LIMIT we want to use. You can change the default of 15 by defining the $rows_per_page parameter:

<?php
  $team = new Pod('team');
  $team->findRecords('name ASC', 20);
?>

If we were to make that change, we’d see all 16 records we have entered, but would also have the same problem once we breached the new limit of 20. A better solution is to include pagination. We’ll revert back to the default limit of 15, and include our pagination links below the Team listing. It’s even easier than it sounds. After you’ve defined your Pod, you can fire the following anywhere:

<?php echo $team->getPagination(); ?>

getPagnination() basically takes care of everything, and will include the pagination controls where echo‘d:

Pagination controls

Here’s the best part, that’s all you’ve got to do. Clicking the second page appends a couple of $_GET variables, reloads the page, and shows you all of your new data. You’re done. There are a few more details concerning getPagination() which will be covered in a subsequent article.

Sorting Pods entries

I’m really excited that the Pods developers are taking so much care with Pods UI. Beyond the inherent user experience improvements it makes, they’re adding features that you can’t even find in WordPress yet. One of my most welcomed additions as of late with Pods UI is the inclusion of drag and drop sorting of Pods entries. Before the functionality was implemented, you had to make a number column in your Pod, and instruct users to use that field to manually order the Pods entries. It was a replication of the limited functionality WordPress offers with Pages. The Pods developers did one better and included such functionality in Pods UI. As with every other aspect of Pods, it’s super easy to integrate, we’ll walk through it quickly.

The first step carries over from the old way of doing things, you’ll need to add a number column to your Pod. We’ll continue working with our Team Pod:

Adding our number column

Once the column is added, we’re going to need to modify our theme template to ORDER BY that column as opposed to the name column it’s currently using:

<?php
  $team = new Pod('team');
  $team->findRecords('displayorder ASC');
  $total_members = $team->getTotalRows();
?>

Easy enough. You could actually leave things as is, and your user could manually edit each of the displayorder columns for each Pod entry, but Pods UI makes that so much easier. We’ll need to modify our custom UI plugin and include a few choice flags that will tell Pods UI the details it needs to enable drag and drop sorting. Our revised plugin is as follows:

<?php
/*
Plugin Name: Team Pods UI
Plugin URI: http://example.com/
Description: Customized Pods UI
Version: 0.1
Author: Jonathan Christopher
Author URI: http://jchristopher.me/
*/

function pods_ui_team()
{
  $icon = '';
  add_object_page('Team', 'Team', 'read', 'team', '', $icon);
  add_submenu_page('team', 'Team', 'Team', 'read', 'team', 'team_page');
}

function team_page()
{
  $object = new Pod('team');
  $add_fields = $edit_fields = array(
        'name',
        'position',
        'photo',
        'bio',
        'permalink',
        'eom');
  $object->ui = array(
        'title'   => 'Team',
        'reorder' => 'displayorder',
        'reorder_columns' => array(
             'name'      => 'Name',
             'position'  => 'Position'),
        'columns' => array(
             'name'      => 'Name',
             'position'  => 'Position',
             'created'   => 'Date Created',
             'modified'  => 'Last Modified'
             ),
        'add_fields'  => $add_fields,
        'edit_fields' => $edit_fields
		);
  pods_ui_manage($object);
}

add_action('admin_menu','pods_ui_team');

?>

While it looks very similar to the Pods UI plugin we developed earlier, you’ll want to note the subtle difference:

'reorder' => 'displayorder',
'reorder_columns' => array(
     'name'      => 'Name',
     'position'  => 'Position'),

These new entries are very important, as they enable the sorting itself, as well as tell Pods which column to use when applying the new sort order. When you break it down it’s quite simple. You define reorder with the number column you set up and would like to use to control the sort order, and reorder_columns are the table columns that appear on the reorder page in the WordPress admin. After modifying your plugin with the following, a new element will be included on the listing page:

Our new Reorder button

Clicking that button will reload the page and bring the user to a page dedicated to managing the order of the Pods entries:

Our new Reorder page

Beautiful! Our user can drag and drop to reorder their entries on the fly, click Update Order at the bottom, and everything is taken care of for us.

Pods never disappoints

I hope that these last couple basic features give you enough information to really get started working with Pods. The developers have really put a lot of time, effort, love, and thought into the implementation and I can’t thank them enough. If you’ve found yourself embracing Pods, please take a moment and donate to the project as I know for a fact they’re working night and day to make Pods that much better with every release.

The Pods CMS Series on MBN

This article is the sixth in a series for Monday By Noon dedicated to Pods CMS.

  1. An Overview of and Introduction to Pods CMS for WordPress
  2. Pods Basics: Installation and Setup
  3. Pods Basics: Pulling Pods Data to your Theme
  4. Pods UI: The Latest and Greatest Addition to Pods
  5. How to use Pick Columns (Relationships) in Pods
  6. The Last of the Pods Basics: Pagination and Sorting

There's a conversation brewing

  1. Thanks so much for these pods tutorials. I only recently discovered pods and ever since your tuts have been my bible.

    So thanks! :-)

  2. Thank you Jonathan for writing this series. Although I was using Pods CMS and Pods UI before I found your posts, this was a good back to basics and from the ground up teaching. And it even showed me some stuff I didn’t know about. I can honestly say that I’m now a more efficient Pods CMS and Pods UI user!

  3. I tried Pods a while back and found it quite interesting. However, the big problem for me is that it kind of sits “on top of” and “aside” from the core WP functionality.

    What I mean is this: you can’t use popular plugins on Pods pages (for example, maybe you want to add Wp_Polls to a Pod page) and it doesn’t integrate with other built in WordPress features such as Search — there’s no out of the box way of having a search on your site that will search the WP data AND the Pods data.

    Sure, you can program all this stuff if you have time time, knoweldge and inclination, but it’s a lot of effort and many who are using WP to build sites don’t have “proper” programming knowledge. For this reason, I think if you’ve got to the point with customising WordPress where Pods is your next step, I really think you should be using a more appropriate system in the first place, such as Expression Engine. At the end of the day, WP core isn’t really built to be a flexible CMS and while I really do applaud the Pods team for an amazing plugin, it just feels like yet another “hack” to make WP do something clever.

    It’s kinda pointless trying to fit a square peg into a round hole. Get hold of the round peg to begin with.

    Of course, I’m a bit out of date with my Pods knowledge, so if some of these problems have now been addressed, perhaps it does make the system more viable? I’d be interested to know.

    • Your concerns are definitely valid, Matt. I’ve developed a, for lack of a better word, theory on integrating Pods while keeping in line with WordPress’ intended functionality but you’re right: there’s a point where the two simply don’t gel as originally intended. What’s great though, is that the Pods devs have done everything they can to mimic that functionality by implementing things like pods_navigation() to use in conjunction with the WordPress functions we all know and love. It’s a it more work, sure, but the stone has been laid.

      It sounds like you’re a seasoned EE developer, and when it comes down to it, it’s about finding the right tool for the job. Many EE devs feel that WordPress pigeonholes a website into a blog-oriented platform and that’s a stigma WordPress will deal with likely for the rest of its life. Personally, I think WordPress is much more friendly for the end user, and if it takes a small bit of creativeness on the development end, that’s okay (for the most part). The end goal is to have the best platform for our clients to use, and if everything you implement on the WordPress end is totally janky, ExpressionEngine would have probably been a better choice.

      Thanks so much for your thoughtful response!

  4. I don’t understand how I can include

    $team = new Pod(‘team’);

    in say, footer.php. I get an error that the class “Pod” is not found.

    • Is Pods installed and activated?

    • Yes Pods is installed and working just fine. Basically I want to display sponsor images in footer.php of my template. I defined a sponsors pod and now I want to use it on my template page.

      findRecords(‘displayorder ASC’);
      $total_members = $sponsors->getTotalRows();
      ?>

      0 ) : ?>
      fetchRecord() ) : ?>

      get_field(‘id’);
      $sponsor_name = $team->get_field(‘name’);
      $sponsor_photo = $team->get_field(‘image’);
      $sponsor_url = $team->get_field(‘url’);
      ?>
      <div class="sponsor" id="sponsor_”>
      <a href="” target=”_blank”><img src="” alt=”" />

      Do I need to do a require_once and point it to pods/core/Pod.class.php? I tried that and I get a fatal error on sanitize().

  5. Ok so I figured it out, I did end up using require_once and it worked. The problem was not changing
    $sponsor_name = $team->get_field(‘name’);

    $team should be $sponsors

    I think if possible maybe note that using a line like

    require_once(WP_PLUGIN_DIR . ‘/pods/core/Pod.class.php’);

    when using Pods in a WordPress template file.

  6. What would be the easiest way to display a team profile photo in the Pods UI column?

  7. Thank You! Excelent script!

  8. So two questions for you all. First, how would you sort the ‘Name’ column based on the displayorder and not alphabetically? If you notice that it flips order when you do reorder. My users are confused because they expect things to be in the same order from the Manage to Reorder pages.

    Also, how about displaying a thumbnail in the table? Is there a way to intercept the table builder to insert an image tag, or somehow use a display helper for it?

    Thanks!

    • $object -> findRecords(‘displayorder ASC’, 25);

      so simple it hurts

    • Glad you were able to discover the fix!

    • Hey boys,
      I wanna do exactly the same. I wrote your line Todd right here in the team_page()-function:
      $object = new Pod(‘showcase’);
      $object->findRecords(‘displayorder ASC’);

      But it has no effect :( the order stays alphabetically. What do I wrong?

    • Some more background info will be necessary, can you link screenshots of your Pods columns as well as a sample entry?

    • Yo Jon.. this is the 3rd time I try to post this. Last try. Maybe something with your comment-function isn’t alright.

      I found an easier way which worked for me, I just added the key-value-pair “‘sort’ => ‘displayorder ASC’” into the $object->ui – Array, and it works just fine :)

  9. Jonathan,

    I’ve been developing websites with WP for only 1 year and it’s the platform I want to master. Recently I’ve been studying ways to make WP work more like a CMS and came across several plugins (More Fields, Custom Field Template, Flutter, CMS Press and Pods CMS). I guess Pods is the winner after reading your tutorial series. So I’ll try to implement it on my company’s new portfolio website. But I have a doubt.
    I’m intending to use picasa for storing and managing each job’s album of pictures and video. WP has a plugin that handles this quite nicely called Shashin. This plugin lets me add thumbnails of a picasa album to a post using a lightbox javascript to zoom in. Do you think it’s possible to integrate this functionality in a Portfolio Pod? Shashin supports shortcodes. ex: [sthumbs=10|8|7|6|5|4|3|2|1,max,3,n,center,]

    • Integrating with another Web service is absolutely within the realm of Pods! I would suggest hopping on the forum and putting out a request for some help if you’re thinking of heading in that direction.

  10. Hey Jonathan,
    Thank you for this intro to Pods… I’ve been meaning to look into it and really found your articles to be very easy to digest. You gave just the right amount of info with great examples.
    Thanks again!

  11. Thanks Jonathan for a great intro to Pods. I had never heard of it just one hour ago, although I’ve been building a few websites in WordPress for about 9 months now. I will look for ways that I might be able to use it on upcoming projects. When I do I’ll be back to study your tutorial again. Anyhow, just wanted to say many thanks for taking the time to create such a great tutorial on the subject.

  12. Hi Jonathan,

    These articles have been indispensable, especially the info on sorting. I’m wondering how this functionality could be used inside a pod entry. For example, I have a pod that can create slideshows in shadowbox. Many images can be associated with a slideshow, but I can’t seem to figure out how to reorder images once they have been uploaded. I’d like to be able to resort them rather than having to “x” them out and add them back in the new order. I can sort the entries in a pod fine now, thanks to you, but can’t seem to figure this out…

    Or maybe this sort of thing just supposed to be handled by an input-manager?

    In any case, it would be great to hook into something already there!

  13. I would like to second James’ question for sorting within a pod entry.

    Also i just figured your sorting method to be only available to the pod admin. Where can I enable other authors to re-order the items?

By all means, contribute

Leave a comment