Comment permalinks only work on the 1st page of comments
Keyz - June 22, 2009 - 00:28
| Project: | Blueprint |
| Version: | 6.x-1.2 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
I noticed that on comments that span multiple pages the comment # permalinks (in comment.tpl.php) do not work correctly (they work on the initial page, but subsequent pages do not receive the ?page=# part of the URL, and consequently do not work at all).
I've found an alternate code snippet in Advanced Forum module (thanks Michelle!) that fixes this. This function of course goes in template.php, and the line in comment.tpl.php would be replaced with simply <?php print $comment_link; ?>.
I have slightly adjusted the original snippet to remove its dependency on Advanced Forum. Feel free to adjust it further if I've missed anything (I'm not an expert yet).
function blueprint_preprocess_comment($vars) {
/**
* Create a permalink with comment # for each comment.
* From Advanced Forum module.
*/
if (!isset($post_number)) {
static $post_number = 0;
}
$post_per_page = _comment_get_display_setting('comments_per_page', $variables['node']);
$page_number = $_GET['page'];
if (!$page_number) {
$page_number = 0;
}
$post_number++;
$fragment = 'comment-' . $variables['comment']->cid;
$query = ($page_number) ? 'page=' . $page_number : NULL;
$linktext = '#' . (($page_number * $post_per_page) + $post_number);
$linkpath = 'node/' . $variables['node']->nid;
$variables['comment_link'] = l($linktext, $linkpath, array('query' => $query, 'fragment' => $fragment));;
}
#1
Upon closer investigation, I realized that not only was the pager not working but the comment count on each comment was getting reset on each page.
Attached is a patch that fixes both the count and the permalink to account for the pager.
#2
Committed [#281116]
#3
#4
Automatically closed -- issue fixed for 2 weeks with no activity.