1

我想打印 taxonomy_vocabulary_11 数组的所有结果(这是 Drupal 7 站点)。如果我使用<?php print render($content['taxonomy_vocabulary_11'][0]['#title']); ?>,我只会得到一个结果。

我已经成功地尝试过

<?php foreach ($content->taxonomy_vocabulary_11 as $key => $value): $terms = $value['#title']; ?>
<?php print $terms; ?>
<?php endforeach?>

我收到此错误:Notice: Trying to get property of non-object

现在,这是我使用开发模块(dpm($node);)得到的输出

(object) array(
  'vid' => '5178',
  'uid' => '1',
  'title' => 'PROYECTO',
  'log' => '',
  'status' => '1',
  'comment' => '2',
  'promote' => '0',
  'sticky' => '0',
  'nid' => '155',
  'type' => 'jornadas',
  'language' => 'und',
  'created' => '1095048000',
  'changed' => '1360589684',
  'tnid' => '0',
  'translate' => '0',
  'revision_timestamp' => '1360589684',
  'revision_uid' => '1',
  'taxonomy_vocabulary_4' => array(),
  'taxonomy_vocabulary_6' => array(
    'und' => array(
      array(
        'tid' => '33',
        'taxonomy_term' => (object) array(
            'tid' => '33',
            'vid' => '6',
            'name' => 'Jornadas Gratuitas',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_6',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_7' => array(
    'und' => array(
      array(
        'tid' => '40',
        'taxonomy_term' => (object) array(
            'tid' => '40',
            'vid' => '7',
            'name' => 'Para PH',
            'description' => '',
            'format' => NULL,
            'weight' => '-10',
            'vocabulary_machine_name' => 'vocabulary_7',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_11' => array(
    'und' => array(
      array(
        'tid' => '262',
        'taxonomy_term' => (object) array(
            'tid' => '262',
            'vid' => '11',
            'name' => 'colegios',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
      array(
        'tid' => '543',
        'taxonomy_term' => (object) array(
            'tid' => '543',
            'vid' => '11',
            'name' => 'derecho',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
    ),
  ),
  'body' => array(
    'und' => array(
      array(
        'value' => "

我还尝试<?php print render($content['taxonomy_vocabulary_11']); ?>将分类法视为任何其他领域,但它不会打印任何内容。

注意:如果我去做print $content['taxonomy_vocabulary_11'];,只需打印单词数组。

我的方法有什么问题?

4

2 回答 2

1

尝试:

foreach ($content['taxonomy_vocabulary_11'] as $tv11) {
    print render($tv11['#title']);
}

我不使用drupal,但如果我了解 $content['taxonomy_vocabulary_11'] 数组的结构,这应该可以工作。

于 2013-02-12T15:05:08.013 回答
0

以防万一有人需要它:

<?php 
$vid = 11; //vocabulary id
$nid = $node->nid; //it looks for the current loaded node
$query = "SELECT tid, name
FROM (
SELECT td.tid AS tid, name
FROM taxonomy_term_data AS td
JOIN taxonomy_index AS tn
  ON td.tid = tn.tid
JOIN node AS n
  ON n.nid = tn.nid
WHERE td.vid = ". $vid ."
  AND n.status = 1
  AND n.nid = ".$nid."
GROUP BY td.tid
) AS t
ORDER BY name ASC";
$result = db_query($query);
foreach($result as $term) {
      echo l($term->name, "taxonomy/term/$term->tid") . ', ';
}
 ?>
于 2013-02-12T16:28:43.630 回答