Shelley has been writing 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.
First, I added two template variables (entries::prev and entries::next) that calculate number of entries to display and URL to use.
The rest was easy: update template to provide default parameters for number of entries listed and starting position:
TemplateVar page::entries <<.
$entries{
start => $request{args}{start} || 1, # start from 1 by default
display => $request{args}{display} || 20, # display no more than 20 entries
header => $request{isentrypage} ? $entry::prevnext : '', # show entry prev/next
footer => q[$entries::prevnext], # show entries prev/next if necessary
}
.
This code checks if start and display parameters from query string available or uses 1 and 20 by default; it also sets footer to the value of $entries::prevnext template variable, which is defined as follows:
TemplateVar entries::prevnext <<.
<div class="prevnext">$get{join ' | ', grep {length}
$entries::prev ? qq[<a href="$entries::prev{url}"><< Prev $entries::prev{display}</a>] : '',
$entries::next ? qq[<a href="$entries::next{url}">Next $entries::next{display} >></a>] : '',
}</div>
.
This code generates prev/next links. As parameters are not hardcoded anywhere, users can check start and display values as they need (start can even be negative; in this case it will display entries from the end of the list, just like @foo[-2..-1] does).
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:
TemplateVar entry::prevnext <<.
<div class="prevnext">$get{join ' | ', grep {length}
$entries{display => 1, sort => "-modified_on", modified_on => "<$entry{modified_on}", q[<a href="$entry::permalink"><< $entry{title}</a>]},
$entries{display => 1, sort => "+modified_on", modified_on => ">$entry{modified_on}", q[<a href="$entry::permalink">$entry{title} >></a>]},
}</div>
.
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 category => $entry{category}:
TemplateVar entry::prevnext <<.
<div class="prevnext">$get{join ' | ', grep {length}
$entries{display => 1, category => $entry{category}, sort => "-modified_on", modified_on => "<$entry{modified_on}", q[<a href="$entry::permalink"><< $entry{title}</a>]},
$entries{display => 1, category => $entry{category}, sort => "+modified_on", modified_on => ">$entry{modified_on}", q[<a href="$entry::permalink">$entry{title} >></a>]},
}</div>
.