【问题标题】:how can i make a span element in this line of php我如何在这行 php 中创建一个 span 元素
【发布时间】:2014-02-07 08:05:31
【问题描述】:

我应该为 $term['nodes'] 放置一个 span 元素 我试图放在括号之后和之间,但对我没有任何作用

if (isset($term['nodes'])) { $term['name'] = $term['name'] . ' (' . $term['nodes'] . ')'; }

这里是所有功能

    function bootstrap_taxonomy_menu_block($variables) {
  $tree = $variables['items'];
  $config = $variables['config'];

  $num_items = count($tree);
  $i = 0;

  $output = '<ul class="nav nav-pills nav-stacked">';
  foreach ($tree as $tid => $term) {
    $i++;
    // Add classes.
    $attributes = array();
    if ($i == 1) {
      $attributes['class'][] = '';
    }
    if ($i == $num_items) {
      $attributes['class'][] = '';
    }
    if ($term['active_trail'] == '1') {
      $attributes['class'][] = 'active-trail';
    }
    if ($term['active_trail'] == '2') {
      $attributes['class'][] = 'active';
    }

    // Alter link text if we have to display the nodes attached.
    if (isset($term['nodes'])) 
{ 
    $term['name'] = $term['name'] . ' (<span>' . $term['nodes'] . '</span>)'; 
}

    // Set alias option to true so we don't have to query for the alias every
    // time, as this is cached anyway.
    $output .= '<li' . drupal_attributes($attributes) . '>' . l($term['name'], $term['path'], $options = array('alias' => TRUE));
    if (!empty($term['children'])) {
      $output .= theme('taxonomy_menu_block__' . $config['delta'], (array('items' => $term['children'], 'config' => $config)));
    }
    $output .= '</li>';
  }
  $output .= '</ul>';

  return $output;
}

我这对于引导 cdn 类是什么,我已经将函数移到了 drupal 主题的 template.php 上,但是 span 元素在浏览器中是纯文本的

【问题讨论】:

    标签: php twitter-bootstrap drupal html


    【解决方案1】:

    试试这个:

    if (isset($term['nodes'])) 
    { 
        $term['name'] = $term['name'] . ' (<span>' . $term['nodes'] . '</span>)'; 
        echo $term['name']; // To see the output
    }
    

    【讨论】:

    • 我已经尝试过这个解决方案,但这是重复我的术语['nodes'] - 我将使用我的所有功能编辑问题,link,我只需要放置这个跨度,因为我是什么要使用引导 cdn 类,我要为该术语制作徽章['nodes']
    • 然后把echo删掉,就不会重复了
    • 是的,我已经删除了 echo ,但 span 元素仍然是纯文本,我可以发布页面链接以查看结果吗? link
    猜你喜欢
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多