I would like to change the comment/forum links to something like:
TOPIC:
#1
#2
#3
Do you have any idea on how should I do this?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI would like to change the comment/forum links to something like:
TOPIC:
#1
#2
#3
Do you have any idea on how should I do this?
Advanced forum provides what you are looking for out of the box (a #number permalink in the upper left corner of the post) among tons of other useful features for a forum.
You could either simply use that module, or you could look at it's template files to see how it's done. The relevant code seems to be in includes/advanced_forum_preprocess_comment.inc and looks like this.
/* Linked post number */
if (!isset($post_number)) {
static $post_number = 1;
}
$posts_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
$page_number = !empty($_GET['page']) ? $_GET['page'] : 0;
if (!$page_number) {
$page_number = 0;
}
$post_number++;
$linktext = '#' . (($page_number * $posts_per_page) + $post_number);
// Permalink
// You can erase next 3 lines if you wish to use built-in Permalink.
// Template adjusted: $post_link -> $permalink
$uri = entity_uri('comment', $comment);
$uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
$variables['permalink'] = l($linktext, $uri['path'], $uri['options']);
if (!$page_number) { $page_number = 0; }
part necessary? It would just set $page_number
to 0, which is already done from the previous line.
First, if the code is in template_preprocess_comment(&$vars)
, $node->type
needs to be $vars['node']->type
. Also, there isn't the need of a comment counter per each page because the Comment module adds an ID starting with 1 for the top comment. Currently this code works correctly for me with comments on several pages.
function template_preprocess_comment(&$vars) {
$posts_per_page = variable_get('comment_default_per_page_' . $vars['node']->type, 50);
$page_number = !empty($_GET['page']) ? $_GET['page'] : 0;
if (!$page_number) {
$page_number = 0;
}
$linktext = '#' . (($page_number * $posts_per_page) + $vars['id']);
$vars['comment']->uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
$vars['permalink'] = l($linktext, $vars['comment']->uri['path'], $vars['comment']->uri['options']);
}
OK got it to work properly ! In you template.php file (drupal/sites/adress/themes/YOURTHEME/template.php) add:
<?php
function YOURTHEME!_preprocess_comment(&$variables){
/* Easy links to the comment and parent node */
$comment = $variables['comment'];
$node = node_load($comment->nid);
$variables['first_post'] = $node;
// Set the post ID for theming / targetting
$variables['post_id'] = "post-$comment->cid";
/* Linked post number */
if (!isset($post_number)) {
static $post_number = 1;
}
$posts_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
$page_number = !empty($_GET['page']) ? $_GET['page'] : 0;
if (!$page_number) {
$page_number = 0;
}
$post_number++;
$linktext = '#' . (($page_number * $posts_per_page) + $post_number);
// Permalink
// You can erase next 3 lines if you wish to use built-in Permalink.
// Template adjusted: $post_link -> $permalink
$uri = entity_uri('comment', $comment);
$uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
$variables['permalink'] = l($linktext, $uri['path'], $uri['options']);
}
?>
You can type in your css file something like this:
.comment .submitted .permalink{ display: none; }
and no more permalink ;)