- if ($n < $total) {
- my $qs = $q->qs_html(o => $n, l => $l);
- $rv .= qq{ <a\nhref="?$qs"\nrel=next>next</a>}
- }
- if ($o > 0) {
- $rv .= $n < $total ? '/' : ' ';
- my $p = $o - $l;
- my $qs = $q->qs_html(o => ($p > 0 ? $p : 0));
- $rv .= qq{<a\nhref="?$qs"\nrel=prev>prev</a>};
+ if ($o >= 0) { # sort descending
+ my $n = $o + $l;
+ if ($n < $total) {
+ $next = $q->qs_html(o => $n, l => $l);
+ }
+ if ($o > 0) {
+ $join = $n < $total ? '/' : ' ';
+ my $p = $o - $l;
+ $prev = $q->qs_html(o => ($p > 0 ? $p : 0));
+ }
+ } else { # o < 0, sort ascending
+ my $n = $o - $l;
+
+ if (-$n < $total) {
+ $next = $q->qs_html(o => $n, l => $l);
+ }
+ if ($o < -1) {
+ $join = -$n < $total ? '/' : ' ';
+ my $p = $o + $l;
+ $prev = $q->qs_html(o => ($p < 0 ? $p : 0));
+ }