1

我试图在每个标签打印为数组元素之前添加一些 html 代码。  
我的代码:

  $term_links = array();

  foreach ($vars['node']->taxonomy as $term) 
  {
    $term_links[] = l($term->name, 'taxonomy/term/' . $term->tid,
      array(
        'attributes' => array(
          'title' => $term->description
    )));
  }

  $vars['node_terms'] = implode(', ', $term_links);

目前,标签以逗号分隔打印。我想在每个标签元素之前添加一个小图像,img src="tag.png" 我该怎么做?

编辑 - 我当前的代码,仍然无法正常工作。

 if (module_exists('taxonomy')) {

$img  = 'some html';
$text = $img . $term->name;
$path = 'taxonomy/term/' . $term->tid;


$term_links = array();
foreach ($vars['node']->taxonomy as $term) {



  $term_links[] = l($text, $path, array(
    'html' => TRUE,
      'attributes' => array(
        'title' => $term->description
    )));
 }
   $vars['node_terms'] = implode(', ', $term_links);
 }
}
4

1 回答 1

2

Dupal 的 l() 函数有一个选项“html”,您可以将其设置为 TRUE 并使用 IMG + TITLE 作为标题。

这是示例:

$img  = '<img src="..." />';
$text = $img . $term->name;
$path = 'taxonomy/term/' . $term->tid;

$term_links[] = l($text, $path, array(
  'html'       => TRUE,
  'attributes' => array(
    'title' => $term->description
  )
));
于 2012-06-10T20:56:55.567 回答