<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Monday By Noon &#187; sorting</title>
	<atom:link href="http://mondaybynoon.com/tag/sorting/feed/" rel="self" type="application/rss+xml" />
	<link>http://mondaybynoon.com</link>
	<description>A resource for Web designers and developers to read about and discuss their craft.</description>
	<lastBuildDate>Wed, 08 Feb 2012 13:49:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>&#8226; The Last of the Pods Basics: Pagination and Sorting</title>
		<link>http://mondaybynoon.com/feeder/?FeederAction=clicked&#038;feed=Posts+%28RSS2%29&#038;seed=http%3A%2F%2Fmondaybynoon.com%2F20100125%2Fpods-pagination-sorting%2F&#038;seed_title=%26%238226%3B+The+Last+of+the+Pods+Basics%3A+Pagination+and+Sorting</link>
		<comments>http://mondaybynoon.com/20100125/pods-pagination-sorting/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 14:57:57 +0000</pubDate>
		<dc:creator>Jonathan Christopher</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Workbench]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Pods]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://mondaybynoon.com/?p=736</guid>
		<description><![CDATA[To wrap up the Basics of Pods in January, I'd like to cover the last couple items I feel are almost essential in having the user experience of Pods come full circle for both you and your user. Pods offers both pagination and sorting out of the box, and each can be very helpful when it comes to working with the plugin.<br /><p><a href='http://rss.buysellads.com/click.php?z=1269068&k=2ee344414ac81fbb0f9de6ab08e9831e&a=736&c=367890373' target='_blank' rel='nofollow'>
				<img src='http://rss.buysellads.com/img.php?z=1269068&k=2ee344414ac81fbb0f9de6ab08e9831e&a=736&c=367890373' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/2ee344414ac81fbb0f9de6ab08e9831e/zone/1269068' target='_blank'>Advertise here with BSA</a></p>]]></description>
			<content:encoded><![CDATA[<p>The Series on Pods has been quite a success so far. I&#8217;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&#8217;m super happy about that, and I&#8217;d like to close out the initial push on the series with what I&#8217;ll call The Last of the Pods Basics. That is to say, I&#8217;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.</p>
<p>As a quick recap, if you haven&#8217;t read the first five articles in The Series, you will probably find this article a bit confusing. That said, please make sure you&#8217;ve read: <a href="/2010/01/04/introduction-to-pods-cms-wordpress/">An Overview of and Introduction to Pods CMS for WordPress</a>, <a href="/2010/01/04/pods-basics-installation-and-setup/">Pods Basics: Installation and Setup</a>, <a href="/2010/01/04/pulling-pods-data/">Pods Basics: Pulling Pods Data to your Theme</a>, <a href="/2010/01/04/pods-ui-intro/">Pods UI: The Latest and Greatest Addition to Pods</a>, and <a href="/2010/01/11/how-to-use-pick-columns-relationships-in-pods/">How to use Pick Columns (Relationships) in Pods</a>. Being up to speed is essential with this article, as it&#8217;s going to build on the system we&#8217;ve put in place using the previously published articles. You won&#8217;t need to recreate the structure set up in the earlier walk throughs, but knowing the existing implementation will help these instructions remain clear.</p>
<h2>Paginated content in Pods</h2>
<p>Pods comes with pagination <em>built right in</em>, it&#8217;s just a matter of getting it to work the way you want. We&#8217;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 <a href="/2010/01/04/pods-ui-intro/">Pods UI</a> to help manage the content.</p>
<p><img src="/images/pods/paging/01-team-listing.jpg" alt="Our new Team listing" /></p>
<p>If we were to check out our Team page now, we&#8217;d see that the listing has been limited to the <strong>default</strong> 15 records:</p>
<p><img src="/images/pods/paging/02-limited-no-warning.jpg" alt="Team listing" /></p>
<p>Also by default, Pods doesn&#8217;t include any sort of warning that content wasn&#8217;t listed. It shouldn&#8217;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&#8217;re using:</p>
<pre class="sh_php"><code>&lt;?php
  $team = new Pod(&#x27;team&#x27;);
  $team-&gt;findRecords(&#x27;name ASC&#x27;);
?&gt;</code></pre>
<p>As it turns out, <a href="http://pods.uproot.us/codex/findrecords"><code>findRecords</code></a> has more parameters to work with, one of which is the <code>LIMIT</code> we want to use. You can change the default of 15 by defining the <code>$rows_per_page</code> parameter:</p>
<pre class="sh_php"><code>&lt;?php
  $team = new Pod(&#x27;team&#x27;);
  $team-&gt;findRecords(&#x27;name ASC&#x27;, 20);
?&gt;</code></pre>
<p>If we were to make that change, we&#8217;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&#8217;ll revert back to the default limit of 15, and include our pagination links below the Team listing. It&#8217;s even easier than it sounds. After you&#8217;ve defined your Pod, you can fire the following anywhere:</p>
<pre class="sh_php"><code>&lt;?php echo $team-&gt;getPagination(); ?&gt;</code></pre>
<p><code>getPagnination()</code> basically takes care of everything, and will include the pagination controls where <code>echo</code>&#8216;d:</p>
<p><img src="/images/pods/paging/03-pagination.jpg" alt="Pagination controls" /></p>
<p>Here&#8217;s the best part, <strong>that&#8217;s all you&#8217;ve got to do</strong>. Clicking the second page appends a couple of <code>$_GET</code> variables, reloads the page, and shows you all of your new data. <em>You&#8217;re done</em>. There are a few more details concerning <a href="http://pods.uproot.us/codex/getpagination"><code>getPagination()</code></a> which will be covered in a subsequent article.</p>
<h2>Sorting Pods entries</h2>
<p>I&#8217;m really excited that the Pods developers are taking so much care with <a href="/2010/01/04/pods-ui-intro/">Pods UI</a>. Beyond the inherent user experience improvements it makes, they&#8217;re adding features that you can&#8217;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 <code>number</code> 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 <a href="http://ui.podscms.org/">Pods UI</a>. As with every other aspect of Pods, it&#8217;s <em>super easy to integrate</em>, we&#8217;ll walk through it quickly.</p>
<p>The first step carries over from the old way of doing things, you&#8217;ll need to add a <code>number</code> column to your Pod. We&#8217;ll continue working with our Team Pod:</p>
<p><img src="/images/pods/sorting/01-displayorder-col.jpg" alt="Adding our number column" /></p>
<p>Once the column is added, we&#8217;re going to need to modify our theme template to <code>ORDER BY</code> that column as opposed to the <code>name</code> column it&#8217;s currently using:</p>
<pre class="sh_php"><code>&lt;?php
  $team = new Pod(&#x27;team&#x27;);
  $team-&gt;findRecords(&#x27;displayorder ASC&#x27;);
  $total_members = $team-&gt;getTotalRows();
?&gt;</code></pre>
<p>Easy enough. You could actually leave things as is, and your user could manually edit each of the <code>displayorder</code> columns for each Pod entry, but Pods UI makes that so much easier. We&#8217;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 <strong>revised</strong> plugin is as follows:</p>
<pre class="sh_php"><code>&lt;?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 = &#x27;&#x27;;
  add_object_page(&#x27;Team&#x27;, &#x27;Team&#x27;, &#x27;read&#x27;, &#x27;team&#x27;, &#x27;&#x27;, $icon);
  add_submenu_page(&#x27;team&#x27;, &#x27;Team&#x27;, &#x27;Team&#x27;, &#x27;read&#x27;, &#x27;team&#x27;, &#x27;team_page&#x27;);
}

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

add_action(&#x27;admin_menu&#x27;,&#x27;pods_ui_team&#x27;);

?&gt;</code></pre>
<p>While it looks very similar to the Pods UI plugin we developed earlier, you&#8217;ll want to note the subtle difference:</p>
<pre class="sh_php"><code>&#x27;reorder&#x27; =&gt; &#x27;displayorder&#x27;,
&#x27;reorder_columns&#x27; =&gt; array(
     &#x27;name&#x27;      =&gt; &#x27;Name&#x27;,
     &#x27;position&#x27;  =&gt; &#x27;Position&#x27;),</code></pre>
<p>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&#8217;s quite simple. You define <code>reorder</code> with the <code>number</code> column you set up and would like to use to control the sort order, and <code>reorder_columns</code> 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:</p>
<p><img src="/images/pods/sorting/02-reorder-button.jpg" alt="Our new Reorder button" /></p>
<p>Clicking that button will reload the page and bring the user to a page dedicated to managing the order of the Pods entries:</p>
<p><img src="/images/pods/sorting/03-reorder-page.jpg" alt="Our new Reorder page" /></p>
<p><strong>Beautiful!</strong> 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.</p>
<h2>Pods never disappoints</h2>
<p>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, <strong>and thought</strong> into the implementation and I can&#8217;t thank them enough. If you&#8217;ve found yourself embracing Pods, please take a moment and <a href="http://pods.uproot.us/">donate to the project</a> as I know for a fact they&#8217;re working night and day to make Pods that much better with every release.</p>
<h4>The Pods CMS Series on <abbr title="Monday By Noon">MBN</abbr></h4>
<p>This article is the <strong>sixth</strong> in a series for Monday By Noon dedicated to <a href="http://pods.uproot.us/">Pods CMS</a>.</p>
<ol>
<li><a href="/2010/01/04/introduction-to-pods-cms-wordpress/">An Overview of and Introduction to Pods CMS for WordPress</a></li>
<li><a href="/2010/01/04/pods-basics-installation-and-setup/">Pods Basics: Installation and Setup</a></li>
<li><a href="/2010/01/04/pulling-pods-data/">Pods Basics: Pulling Pods Data to your Theme</a></li>
<li><a href="/2010/01/04/pods-ui-intro/">Pods UI: The Latest and Greatest Addition to Pods</a></li>
<li><a href="/2010/01/11/how-to-use-pick-columns-relationships-in-pods/">How to use Pick Columns (Relationships) in Pods</a></li>
<li><a href="/2010/01/25/pods-pagination-sorting/">The Last of the Pods Basics: Pagination and Sorting</a></li>
</ol>
<br /><p><a href='http://rss.buysellads.com/click.php?z=1269068&k=2ee344414ac81fbb0f9de6ab08e9831e&a=736&c=2011801148' target='_blank' rel='nofollow'>
				<img src='http://rss.buysellads.com/img.php?z=1269068&k=2ee344414ac81fbb0f9de6ab08e9831e&a=736&c=2011801148' border='0' alt='' /></a></p><p><a href='http://buysellads.com/buy/sitedetails/pubkey/2ee344414ac81fbb0f9de6ab08e9831e/zone/1269068' target='_blank'>Advertise here with BSA</a></p>]]></content:encoded>
			<wfw:commentRss>http://mondaybynoon.com/20100125/pods-pagination-sorting/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Database Caching 1/48 queries in 0.046 seconds using apc
Object Caching 468/521 objects using apc

Served from: www.mondaybynoon.com @ 2012-02-11 08:48:29 -->
