Revision [16777]

This is an old revision of PagedComments made by KopLow on 2007-05-31 10:47:30.

 

Paged Comments

Last edited by KopLow
Thu, 31 May 2007 10:47 UTC [diff]


When the number of comments at the bottom of a page is too large (there is virtually no limit to their number), the comments block becomes user-unfriendly:

I've written a configurable comments pager to address this issue. The pager allows to switch between a "paged" and a "showall" view. The default number of comments per page is set by a $limit_comments session parameter, that can be changed in UserSettings.
Paged comments come in two "flavours".


Screenshots:

Flavour A) - previous/next links
http://wikka.jsnx.com/images/pagedcomments.jpg

Flavour B) - pagelist
http://wikka.jsnx.com/images/pagedcomments2.jpg



Here's the code.

1. Create function LoadCommentPage() in wikka.php

        function LoadCommentPage($tag, $start, $limit) {
            return $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."comments WHERE page_tag = '".mysql_real_escape_string($tag)."' ORDER BY time LIMIT ".$start.",".$limit);
        }


2. Modify the comments block in handlers/page/show.php

%%(php)
if ($this->GetConfigValue("hide_comments") != 1)
{
set default number of comments per page
$d = ($_SESSION["limit_comments"])? $_SESSION["limit_comments"] : "10";

set default visualization to "paged"
$showall = ($_REQUEST["showall"])? $_REQUEST["showall"] : "0";

get total number of comments for current page
$n = count($this->LoadComments($this->tag));

calculate starting item of last page
$lastcomments = ceil($n/$d)*$d;
$start = ($n > $d)? ($lastcomments-$d) : "0";

set starting item and limit
$s = (isset($_REQUEST["s"]))? $_REQUEST["s"] : $start;
$l = (isset($_REQUEST["l"]))? $_REQUEST["l"] : $d;
set no limits for showall visualization
if ($showall
$s = "0";
$l = "999";
}

Build pager links:

/*
FLAVOUR A) - next/previous links

show "previous" link if needed
if($s > 0) {
$prev = " <a href=\ .$this->Href(,"","l=".$l."
There are 6 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki