i want to show an icon (add more comment) in the bottom of each node..

so i've redeclared the method theme_links, in the template.php file

i've writed this code

function theme_links($links, $attributes = array('class' => 'links')) {
  global $language;
  $output = '';

  if (count($links) > 0) {
    $output = '<div'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;
	//print_r(array_keys($links['comment_add']));print 
	if (isset($links['comment_add']['title']))
	{
		$links['comment_add']['title']='<img src="'.base_path() .'themes/sandium/images/add-comment.png"/>';
	}
    foreach ($links as $key => $link) {
      $class = $key;

      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
          && (empty($link['language']) || $link['language']->language == $language->language)) {
        $class .= ' active';
      }
      $output .= '<span'. drupal_attributes(array('class' => $class)) .'>';

      if (isset($link['href'])) {
        // Pass in $link as $options, they share the same keys.
        $output .= l($link['title'], $link['href'], $link);
      }
      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</span>\n";
    }

    $output .= '</div>';
  }

  return $output;
}

it work's okay, the problem is that i cant view any image...

the image is printed like a text <img src="/test/themes/sandium/images/add-comment.png"/>

so how can i fix this? i want to show an image???

Comments

doeboy’s picture

A brief solution that may help.

In your template.php file

function phptemplate_preprocess_node(&$vars) {
$links = $vars['node']->links;

// ADDING AN image to the link variable.

$links['link-name'] = array("title" => '<img src="image...23.jgp"/>', "href" => 'http://www.apple.com', 'html' => TRUE);
}

make sure the 'html' => TRUE

cheers
David

Wassim Ghannoum’s picture

thanks cheese and bread for the help

i've tried this code:

function phptemplate_preprocess_node(&$vars) {
$links = $vars['node']->links;

// ADDING AN image to the link variable.
$links['comment_add'] = array("title" => '<img src="http://localhost/test/themes/sandium/images/add-comment.png"/>', "href" => 'http://www.apple.com', 'html' => TRUE);
}

but it doesen't work, so i've modified my last code, and i've added $link['html'] = TRUE; before print the $output, and it works great for me, this is the new code

function theme_links($links, $attributes = array('class' => 'links')) {
  global $language;
  $output = '';

  if (count($links) > 0) {
    $output = '<div'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;
	//print_r(array_keys($links['comment_add']));print 
	if (isset($links['comment_add']['title']))
	{
		$links['comment_add']['title']='<img src="'.base_path() .'themes/sandium/images/add-comment.png"/>';
	}
	//print ("<h2>".$links['comment_add']->title."</h2>");
    foreach ($links as $key => $link) {
      $class = $key;

      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
          && (empty($link['language']) || $link['language']->language == $language->language)) {
        $class .= ' active';
      }
      $output .= '<span'. drupal_attributes(array('class' => $class)) .'>';

      if (isset($link['href'])) {
        // Pass in $link as $options, they share the same keys.
        $link['html'] = TRUE;
		$output .= l($link['title'], $link['href'], $link);
      }
      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['html'] = TRUE;//check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</span>\n";
    }

    $output .= '</div>';
  }

  return $output;
}
doeboy’s picture

You need add the final line try this

<?php
function phptemplate_preprocess_node(&$vars) {
$links = $vars['node']->links;

// ADDING AN image to the link variable.
$links['comment_add'] = array("title" => '<img src="http://localhost/test/themes/sandium/images/add-comment.png"/>', "href" => 'http://www.apple.com', 'html' => TRUE);

$vars['links'] = theme('links', $links, array('class' => 'links'));

}
?>
Wassim Ghannoum’s picture

also it doesen't work...

i've made a brief modification to make it working

function phptemplate_preprocess_node(&$vars) {
$links = $vars['node']->links;
$links['comment_add']['title']='<img src="'.base_path() .'themes/sandium/images/add-comment.png"/>';
$links['comment_add']['html']= true;
$links['node_read_more']['title']='<img src="'.base_path() .'themes/sandium/images/read-more.png"/>';
$links['node_read_more']['html']= true;
$vars['links'] = theme('links', $links, array('class' => 'links'));

}