<?xml version="1.0" encoding="utf-8"?>
<!-- generator="Blooki/0.4803" -->
<feed version="0.3" xmlns="http://purl.org/atom/ns#"  xml:lang="en">
  <title mode="escaped" type="text/html">Blooki</title>
  <tagline mode="escaped" type="text/html">Grow what you know</tagline>
  <link rel="alternate" type="text/html" href="http://blooki.org/2004/09/26/.atom/"/>
  <modified>2004-09-26T19:11:00Z</modified>
  <author><name>Paul Kulchenko</name></author>


  <entry>
    <title>Pagination in Blooki</title>
    <content type="text/html" mode="escaped">&lt;p&gt;&lt;a href="http://weblog.burningbird.net/archives/2004/09/20/some-gratuitous-weblog-software-writing/"&gt;Shelley has been writing&lt;/a&gt; about upcoming Wordpress 1.3 release and one of the features that will be included in the release -- pagination. I got curious about how difficult it would be to add something like this to Blooki. &lt;/p&gt;

&lt;p&gt;First, I added two template variables (&lt;code&gt;entries::prev&lt;/code&gt; and &lt;code&gt;entries::next&lt;/code&gt;) that calculate number of entries to display and &lt;span class="caps"&gt;URL &lt;/span&gt;to use.&lt;/p&gt;

&lt;p&gt;The rest was easy: update template to provide default parameters for number of entries listed and starting position:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;TemplateVar page::entries &amp;lt;&amp;lt;.
  $entries{
    start =&amp;gt; $request{args}{start} || 1,      # start from 1 by default
    display =&amp;gt; $request{args}{display} || 20, # display no more than 20 entries
    header =&amp;gt; $request{isentrypage} ? $entry::prevnext : '', # show entry prev/next
    footer =&amp;gt; q[$entries::prevnext], # show entries prev/next if necessary
  }
.
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This code checks if &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;display&lt;/code&gt; parameters from query string available or uses 1 and 20 by default; it also sets footer to the value of &lt;code&gt;$entries::prevnext&lt;/code&gt; template variable, which is defined as follows:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;TemplateVar entries::prevnext &amp;lt;&amp;lt;.
&amp;lt;div class=&amp;quot;prevnext&amp;quot;&amp;gt;$get{join ' | ', grep {length}
  $entries::prev ? qq[&amp;lt;a href=&amp;quot;$entries::prev{url}&amp;quot;&amp;gt;&amp;amp;lt;&amp;amp;lt; Prev $entries::prev{display}&amp;lt;/a&amp;gt;] : '',
  $entries::next ? qq[&amp;lt;a href=&amp;quot;$entries::next{url}&amp;quot;&amp;gt;Next $entries::next{display} &amp;amp;gt;&amp;amp;gt;&amp;lt;/a&amp;gt;] : '', 
}&amp;lt;/div&amp;gt;
.
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This code generates prev/next links. As parameters are not hardcoded anywhere, users can check &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;display&lt;/code&gt; values as they need (&lt;code&gt;start&lt;/code&gt; can even be negative; in this case it will display entries from the end of the list, just like &lt;code&gt;@foo[-2..-1]&lt;/code&gt; does).&lt;/p&gt;

&lt;p&gt;Excited by the ease of the change I also tried to do prev/next links on entries. This didn't required any coding at all; only a small template change:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;TemplateVar entry::prevnext &amp;lt;&amp;lt;.
&amp;lt;div class=&amp;quot;prevnext&amp;quot;&amp;gt;$get{join ' | ', grep {length}
  $entries{display =&amp;gt; 1, sort =&amp;gt; &amp;quot;-modified_on&amp;quot;, modified_on =&amp;gt; &amp;quot;&amp;lt;$entry{modified_on}&amp;quot;, q[&amp;lt;a href=&amp;quot;$entry::permalink&amp;quot;&amp;gt;&amp;amp;lt;&amp;amp;lt; $entry{title}&amp;lt;/a&amp;gt;]},
  $entries{display =&amp;gt; 1, sort =&amp;gt; &amp;quot;+modified_on&amp;quot;, modified_on =&amp;gt; &amp;quot;&amp;gt;$entry{modified_on}&amp;quot;, q[&amp;lt;a href=&amp;quot;$entry::permalink&amp;quot;&amp;gt;$entry{title} &amp;amp;gt;&amp;amp;gt;&amp;lt;/a&amp;gt;]},
}&amp;lt;/div&amp;gt;
.
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This code displays prev/next links with titles of entries (if there is previous/next entry). It's also easy to make it display prev/next entries in a particular category, just add a category filter &lt;code&gt;category =&amp;gt; $entry{category}&lt;/code&gt;:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;TemplateVar entry::prevnext &amp;lt;&amp;lt;.
&amp;lt;div class=&amp;quot;prevnext&amp;quot;&amp;gt;$get{join ' | ', grep {length}
  $entries{display =&amp;gt; 1, category =&amp;gt; $entry{category}, sort =&amp;gt; &amp;quot;-modified_on&amp;quot;, modified_on =&amp;gt; &amp;quot;&amp;lt;$entry{modified_on}&amp;quot;, q[&amp;lt;a href=&amp;quot;$entry::permalink&amp;quot;&amp;gt;&amp;amp;lt;&amp;amp;lt; $entry{title}&amp;lt;/a&amp;gt;]},
  $entries{display =&amp;gt; 1, category =&amp;gt; $entry{category}, sort =&amp;gt; &amp;quot;+modified_on&amp;quot;, modified_on =&amp;gt; &amp;quot;&amp;gt;$entry{modified_on}&amp;quot;, q[&amp;lt;a href=&amp;quot;$entry::permalink&amp;quot;&amp;gt;$entry{title} &amp;amp;gt;&amp;amp;gt;&amp;lt;/a&amp;gt;]},
}&amp;lt;/div&amp;gt;
.
&lt;/code&gt;&lt;/pre&gt;</content>
    <link rel="alternate" type="text/html" href="http://blooki.org/2004/09/26/.atom/development/pagination-in-blooki"/>
    <id>http://blooki.org/2004/09/26/.atom/development/pagination-in-blooki</id>
    <issued>2004-09-26T19:11:00Z</issued>
    <modified>2004-09-26T19:11:00Z</modified>
    
  </entry>


</feed>
