<?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>Made of Everything You&#039;re Not &#187; pagination</title>
	<atom:link href="http://blog.ericlamb.net/tag/pagination/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ericlamb.net</link>
	<description>Thoughts on programming, people and life</description>
	<lastBuildDate>Thu, 27 Oct 2011 01:29:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Worpress Style Pagination</title>
		<link>http://blog.ericlamb.net/2009/02/worpress-style-pagination/</link>
		<comments>http://blog.ericlamb.net/2009/02/worpress-style-pagination/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 07:12:50 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=698</guid>
		<description><![CDATA[I&#8217;ve been working on a new code base for StreetWise these past couple months, getting ready for the upcoming busy season, and as this new code needs to support membership of 1,000,000+ people decided I wanted, no, needed, to rework my pagination algorithm. The Problem Previously, I&#8217;ve gone for a basic approach of just listing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a new code base for StreetWise these past couple months, getting ready for the upcoming busy season, and as this new code needs to support membership of 1,000,000+ people decided I <span style="text-decoration: line-through;">wanted</span>, no, <ins datetime="2009-02-03T06:26:04+00:00">needed</ins>, to rework my pagination algorithm.</p>
<h3>The Problem</h3>
<p>Previously, I&#8217;ve gone for a basic approach of just listing out the links sequentially with a Next and Prev state. For larger page sets, I would just remove the numeric links. For example they would look like the below:</p>
<p>1 <span style="text-decoration: underline;">2</span> <span style="text-decoration: underline;">3</span> <span style="text-decoration: underline;">4</span> <span style="text-decoration: underline;">5</span> etc&#8230;</p>
<p>This becomes problematic at higher numbers though; just imagine the page would look if there were 1,000 pages instead of five. Here&#8217;s an example of just 100:</p>
<p>1 <span style="text-decoration: underline;">2</span> <span style="text-decoration: underline;">3</span> <span style="text-decoration: underline;">4</span> <span style="text-decoration: underline;">5</span> <span style="text-decoration: underline;">6</span> <span style="text-decoration: underline;">7</span> <span style="text-decoration: underline;">8</span> <span style="text-decoration: underline;">9</span> <span style="text-decoration: underline;">10</span> <span style="text-decoration: underline;">11</span> <span style="text-decoration: underline;">12</span> <span style="text-decoration: underline;">13</span> <span style="text-decoration: underline;">14</span> <span style="text-decoration: underline;">15</span> <span style="text-decoration: underline;">16</span> <span style="text-decoration: underline;">17</span> <span style="text-decoration: underline;">18</span> <span style="text-decoration: underline;">19</span> <span style="text-decoration: underline;">20</span> <span style="text-decoration: underline;">21</span> <span style="text-decoration: underline;">22</span> <span style="text-decoration: underline;">23</span> <span style="text-decoration: underline;">24</span> <span style="text-decoration: underline;">25</span> <span style="text-decoration: underline;">26</span> <span style="text-decoration: underline;">27</span> <span style="text-decoration: underline;">28</span> <span style="text-decoration: underline;">29</span> <span style="text-decoration: underline;">30</span> <span style="text-decoration: underline;">31</span> <span style="text-decoration: underline;">32</span> <span style="text-decoration: underline;">33</span> <span style="text-decoration: underline;">34</span> <span style="text-decoration: underline;">35</span> <span style="text-decoration: underline;">36</span> <span style="text-decoration: underline;">37</span> <span style="text-decoration: underline;">38</span> <span style="text-decoration: underline;">39</span> <span style="text-decoration: underline;">40</span> <span style="text-decoration: underline;">41</span> <span style="text-decoration: underline;">42</span> <span style="text-decoration: underline;">43</span> <span style="text-decoration: underline;">44</span> <span style="text-decoration: underline;">45</span> <span style="text-decoration: underline;">46</span> <span style="text-decoration: underline;">47</span> <span style="text-decoration: underline;">48</span> <span style="text-decoration: underline;">49</span> <span style="text-decoration: underline;">50</span> <span style="text-decoration: underline;">51</span> <span style="text-decoration: underline;">52</span> <span style="text-decoration: underline;">53</span> <span style="text-decoration: underline;">54</span> <span style="text-decoration: underline;">55</span> <span style="text-decoration: underline;">56</span> <span style="text-decoration: underline;">57</span> <span style="text-decoration: underline;">58</span> <span style="text-decoration: underline;">59</span> <span style="text-decoration: underline;">60</span> <span style="text-decoration: underline;">61</span> <span style="text-decoration: underline;">62</span> <span style="text-decoration: underline;">63</span> <span style="text-decoration: underline;">64</span> <span style="text-decoration: underline;">65</span> <span style="text-decoration: underline;">66</span> <span style="text-decoration: underline;">67</span> <span style="text-decoration: underline;">68</span> <span style="text-decoration: underline;">69</span> <span style="text-decoration: underline;">70</span> <span style="text-decoration: underline;">71</span> <span style="text-decoration: underline;">72</span> <span style="text-decoration: underline;">73</span> <span style="text-decoration: underline;">74</span> <span style="text-decoration: underline;">75</span> <span style="text-decoration: underline;">76</span> <span style="text-decoration: underline;">77</span> <span style="text-decoration: underline;">78</span> <span style="text-decoration: underline;">79</span> <span style="text-decoration: underline;">80</span> <span style="text-decoration: underline;">81</span> <span style="text-decoration: underline;">82</span> <span style="text-decoration: underline;">83</span> <span style="text-decoration: underline;">84</span> <span style="text-decoration: underline;">85</span> <span style="text-decoration: underline;">86</span> <span style="text-decoration: underline;">87</span> <span style="text-decoration: underline;">88</span> <span style="text-decoration: underline;">89</span> <span style="text-decoration: underline;">90</span> <span style="text-decoration: underline;">91</span> <span style="text-decoration: underline;">92</span> <span style="text-decoration: underline;">93</span> <span style="text-decoration: underline;">94</span> <span style="text-decoration: underline;">95</span> <span style="text-decoration: underline;">96</span> <span style="text-decoration: underline;">97</span> <span style="text-decoration: underline;">98</span> <span style="text-decoration: underline;">99</span> <span style="text-decoration: underline;">100</span> </p>
<p>So it can be a bit of a problem.</p>
<h3>The Replacement</h3>
<p>A lot of websites are using a better pagination style that&#8217;s sometimes called WordPress pagination. This pagination style presents only a few links at a time while still allowing more freedom than the basic <span style="text-decoration: underline;">Next</span>  <span style="text-decoration: underline;">Prev</span>  style. Here&#8217;s an example:</p>
<p><span style="text-decoration: underline;">« Previous</span> <span style="text-decoration: underline;">1</span> <span style="text-decoration: underline;">2</span> <span style="text-decoration: underline;">3</span> &#8230; <span style="text-decoration: underline;">10</span> <span style="text-decoration: underline;">11</span> <span style="text-decoration: underline;">12</span> <span style="text-decoration: underline;">13 </span><span style="text-decoration: underline;">14</span> &#8230; <span style="text-decoration: underline;">118</span> <span style="text-decoration: underline;">119</span> <span style="text-decoration: underline;">120</span> <span style="text-decoration: underline;">Next »</span></p>
<h3>The Solution</h3>
<p>Being it&#8217;s called WordPress pagination, and that I&#8217;m a <em>lazy</em> php programmer, I just stole the code from WordPress and translated it into something a little more portable.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> paginate_links<span style="color: #000;">&#40;</span><span style="color: #000088;">$format</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'?page=%#%'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'%_%'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$show_all</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prev_next</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prev_text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&amp;laquo; Previous'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$next_text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Next &amp;raquo;'</span><span style="color: #339933;">,</span><span style="color: #000088;">$end_size</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'3'</span><span style="color: #339933;">,</span><span style="color: #000088;">$mid_size</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'2'</span><span style="color: #339933;">,</span><span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'plain'</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #000;">&#40;</span>int<span style="color: #000;">&#41;</span> <span style="color: #000088;">$total</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$total</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		<span style="color: #22f;">return</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
	<span style="color: #000088;">$current</span>  <span style="color: #339933;">=</span> <span style="color: #000;">&#40;</span>int<span style="color: #000;">&#41;</span> <span style="color: #000088;">$current</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$end_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>  <span style="color: #339933;">&lt;</span> <span style="color: #000;">&#40;</span>int<span style="color: #000;">&#41;</span> <span style="color: #000088;">$end_size</span> ? <span style="color: #000;">&#40;</span>int<span style="color: #000;">&#41;</span> <span style="color: #000088;">$end_size</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Out of bounds?  Make it the default.</span>
	<span style="color: #000088;">$mid_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000;">&#40;</span>int<span style="color: #000;">&#41;</span> <span style="color: #000088;">$mid_size</span> ? <span style="color: #000;">&#40;</span>int<span style="color: #000;">&#41;</span> <span style="color: #000088;">$mid_size</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$page_links</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$dots</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$prev_next</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$current</span> <span style="color: #000;">&#41;</span><span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'%_%'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$current</span> ? <span style="color: #0000ff;">''</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$format</span><span style="color: #339933;">,</span> <span style="color: #000088;">$base</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'%#%'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$add_fragment</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$page_links</span><span style="color: #000;">&#91;</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;a class='prev page-numbers' href='&quot;</span> <span style="color: #339933;">.</span> clean_url<span style="color: #000;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&gt;<span style="color: #006699; font-weight: bold;">$prev_text</span>&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #22f;">for</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$n</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$total</span><span style="color: #339933;">;</span> <span style="color: #000088;">$n</span><span style="color: #339933;">++</span> <span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$n_display</span> <span style="color: #339933;">=</span> <span style="color: #990000;">number_format</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$n</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$n</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$current</span> <span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
			<span style="color: #000088;">$page_links</span><span style="color: #000;">&#91;</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;span class='page-numbers current'&gt;<span style="color: #006699; font-weight: bold;">$n_display</span>&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$dots</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #000;">&#125;</span> <span style="color: #22f;">else</span> <span style="color: #000;">&#123;</span>
			<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$show_all</span> <span style="color: #339933;">||</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$n</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$end_size</span> <span style="color: #339933;">||</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$n</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$mid_size</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$n</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$mid_size</span> <span style="color: #000;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$n</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$total</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$end_size</span> <span style="color: #000;">&#41;</span> <span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
				<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'%_%'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$n</span> ? <span style="color: #000088;">$format</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$format</span><span style="color: #339933;">,</span> <span style="color: #000088;">$base</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'%#%'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$n</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$link</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$add_fragment</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$page_links</span><span style="color: #000;">&#91;</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;a class='page-numbers' href='&quot;</span> <span style="color: #339933;">.</span> clean_url<span style="color: #000;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&gt;<span style="color: #006699; font-weight: bold;">$n_display</span>&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$dots</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #000;">&#125;</span> <span style="color: #22f;">elseif</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$dots</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$show_all</span> <span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
				<span style="color: #000088;">$page_links</span><span style="color: #000;">&#91;</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;span class='page-numbers dots'&gt;...&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$dots</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #000;">&#125;</span>
		<span style="color: #000;">&#125;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$prev_next</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$total</span> <span style="color: #339933;">||</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$total</span> <span style="color: #000;">&#41;</span> <span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'%_%'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$format</span><span style="color: #339933;">,</span> <span style="color: #000088;">$base</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'%#%'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$link</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$add_fragment</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$page_links</span><span style="color: #000;">&#91;</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;a class='next page-numbers' href='&quot;</span> <span style="color: #339933;">.</span> clean_url<span style="color: #000;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&gt;<span style="color: #006699; font-weight: bold;">$next_text</span>&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #22f;">switch</span> <span style="color: #000;">&#40;</span> <span style="color: #000088;">$type</span> <span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		<span style="color: #22f;">case</span> <span style="color: #0000ff;">'array'</span> <span style="color: #339933;">:</span>
			<span style="color: #22f;">return</span> <span style="color: #000088;">$page_links</span><span style="color: #339933;">;</span>
			<span style="color: #22f;">break</span><span style="color: #339933;">;</span>
		<span style="color: #22f;">case</span> <span style="color: #0000ff;">'list'</span> <span style="color: #339933;">:</span>
			<span style="color: #000088;">$r</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;ul class='page-numbers'&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;li&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$r</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">join</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/li&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;li&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page_links</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$r</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/li&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/ul&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #22f;">break</span><span style="color: #339933;">;</span>
		<span style="color: #22f;">default</span> <span style="color: #339933;">:</span>
			<span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page_links</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #22f;">break</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #22f;">return</span> <span style="color: #000088;">$r</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>As you can see, especially if you&#8217;re already familiar with WordPress, all I&#8217;ve done is take out the WordPress specific functions and set the $args to function parameters. Pure theft <img src='http://blog.ericlamb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>There are a bunch of paramaters and options you can configure the links by but only the first 3 are really needed to make the function work.</p>
<p>Here&#8217;s an example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$numofpages</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'4'</span>
<span style="color: #000088;">$query_string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'foo='</span><span style="color: #339933;">.</span><span style="color: #000088;">$foo</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;bar='</span><span style="color: #339933;">.</span><span style="color: #000088;">$bar</span><span style="color: #339933;">;</span>
<span style="color: #22f;">echo</span> paginate_links<span style="color: #000;">&#40;</span><span style="color: #0000ff;">'?'</span><span style="color: #339933;">.</span><span style="color: #000088;">$query_string</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;page=%#%'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$numofpages</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I didn&#8217;t put too much work into this, which is kinda the point, but I hope it&#8217;s helpful!</p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2009/02/worpress-style-pagination/' addthis:title='Worpress Style Pagination '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/02/worpress-style-pagination/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

