You are here

Creating node permalink in Drupal 7

Last post
4 posts / 0 new
Dan
Dan's picture
Offline
Last seen: 36 min 12 sec ago
Joined: Jun 2012
Points: 377

Creating node permalink in Drupal 7

Permalink link for comments already exist, but for node (blog post, forum topic etc.) there is no permalink link in node links, and unfortunately we have to do some coding since to my knowledge there is no module for this (Drupal 7). My point of view for permalink is a short URL from the node (the original URL before the URL aliased).

Open template.php in your theme folder, let say you still use the default theme Bartik. Paste or update below code:

/**
* Override or insert variables into the node template.
*/
function bartik_preprocess_node(&$variables) {
  if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
    $variables['classes_array'][] = 'node-full';
  }
}

To

/**
* Override or insert variables into the node template.
*/
function bartik_preprocess_node(&$variables) {
  if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
    $variables['classes_array'][] = 'node-full';
  }

  $node = $variables['node'];
  global $base_url;
  // Add your own custom link
  $links = $variables['content']['links']['node']['#links']['permalink'] = array(
    'title' => t('Permalink'),
    'href' => $base_url . '/node/' . $node->nid,
    'html' => TRUE,
    'attributes' => array(
      'title' => 'Permalink',
      'rel' => 'bookmark',
      'class' => 'permalink',
    ),
  );
  return $links;
}

To create permalink links to nodes that use the path alias (ie already aliased using Pathauto module) then use code as follows:

/**
* Override or insert variables into the node template.
*/
function bartik_preprocess_node(&$variables) {
  if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
    $variables['classes_array'][] = 'node-full';
  }

  $node = $variables['node'];
  // Add your own custom link
  $links = $variables['content']['links']['node']['#links']['permalink'] = array(
    'title' => t('Permalink'),
    'href' => 'node/' . $node->nid,
    'html' => TRUE,
    'attributes' => array(
      'title' => 'Permalink',
      'rel' => 'bookmark',
      'class' => 'permalink',
    ),
  );
  return $links;
}

Dan,
Follow me danpros and danbz.

luxiezas's picture
Offline
Last seen: 1 day 20 hours ago
Joined: Feb 2013
Points: 76

nice

nice sharing dan

Septictankbiorich.comBiotech System
SeptictankbiorichBioRich, Biotech, Biofil
Surya Utama FibertechFibreglass

hirumangun's picture
Offline
Last seen: 2 months 2 weeks ago
Joined: Mar 2013
Points: 5

someday

I hope understand drupal someday, I have to learn it Fool

Offline
Last seen: 2 weeks 3 days ago
Joined: Apr 2013
Points: 4

wow drupal, i realy don't

wow drupal, i realy don't undestand about it, maybe i must learn about drupal, yeah