вывод материалов терминов каталога html списком + вывод дочерних терминов словаря с глубиной [РЕШЕНО]

Главные вкладки

Аватар пользователя leramulina leramulina 12 июля 2011 в 3:38

Господа, я бьюсь целый день и никак не могу найти решения. Надеюсь, что вы не будете тыкать меня носом в поиск на этом сайте или на Гугле, а подскажете более гуманное и информативное решение.

Я пыталась вывести материалы терминов каталога html списком + вывод дочерних терминов словаря с глубиной. Сначала я добавила в template.php :

<?phpfunction framework_taxonomy_term_page($tids, $result) 
{
drupal_add_css(drupal_get_path('module', 'taxonomy') .'/taxonomy.css');
$output = '<div id="category-item-list">';
// Only display the description if we have a single term, to avoid clutter and confusion.
if (count($tids) == 1) {
     $term = taxonomy_get_term($tids[0]);
     $description = $term->description;
// Check that a description is set.
if (!empty($description)) 
{
       $output .= '<div class="taxonomy-term-description">';
       $output .= filter_xss_admin($description);
       $output .= '</div>';
}
}

$children_terms = taxonomy_get_children($term->tid);
if ($children_terms) {
$children_terms = taxonomy_get_children($term->tid);
foreach ($children_terms as $children_term ) 
{
$t_children_count = taxonomy_term_count_nodes($children_term->tid);
$children_items[] = l($children_term->name .' ('. $t_children_count .')','taxonomy/term/'. $children_term->tid, array('attributes' => array('title' => $children_term->name)));
}
$output .= theme('item_list', $children_items, t('Subsections'));
}

while ($node = db_fetch_object($result)) 
{
   $items[] = node_view(node_load($node->nid), TRUE);
   }
   $output .= theme('item_list', $items, t('Publications'), 'ul',array('class'=>'pub-list'));
   $output .= theme('pager', NULL, variable_set('default_nodes_main', 40), 0);
   $output .= '</div>';
   return $output;
}?>

Получила в просмотре термина вывод тизеров и дочерних терминов. Но дочерние термины здесь идут только в один уровень, а мне нужен список на всю глубину. Попытки переписать $children_terms = taxonomy_get_children ничего не дали, потому что я пока не разбираюсь в php.

Потом я попробовала сделать почти то же, но через views. Я сделала views выводящий термины в taxonomy/term/% через определенные поля в виде html списка. И я так поняла, что для вывода дочерних терминов с глубиной, мне надо найти сниппет для шапки. Но все сниппеты, что я находила, не выводили мне этого самого списка с глубиной.

Помогите. Подскажите, пожалуйста, как реализовать вывод дочерних терминов с глубиной либо через изменение template, либо через код в шапку views.

Спасибо.

UPD: http://www.drupal.ru/node/46026 нашла код здесь

Комментарии

Аватар пользователя Orion76 Orion76 12 июля 2011 в 4:33

может быть это:

<?php
/**
 * Create a hierarchical representation of a vocabulary.
 *
 * param $vid
 *   Which vocabulary to generate the tree for.
 *
 * param $parent
 *   The term ID under which to generate the tree. If 0, generate the tree
 *   for the entire vocabulary.
 *
 * param $depth
 *   Internal use only.
 *
 * param $max_depth
 *   The number of levels of the tree to return. Leave NULL to return all levels.
 *
 * return
 *   An array of all term objects in the tree. Each term object is extended
 *   to have "depth" and "parents" attributes in addition to its normal ones.
 *   Results are statically cached.
 */
function taxonomy_get_tree($vid$parent 0$depth = -1$max_depth NULL)
?>
Аватар пользователя leramulina leramulina 12 июля 2011 в 4:48

Вот такая штука в шапке views "работает", но опять же выводит только один уровень без глубины.

<?php
function taxonomy_get_children($tid, $vid = 0) {
$children = &drupal_static(__FUNCTION__, array());

if ($tid && !isset($children[$tid])) {
$query = db_select('taxonomy_term_data', 't');
$query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
$query->addField('t', 'tid');
$query->condition('h.parent', $tid);
if ($vid) {
$query->condition('t.vid', $vid);
}
$query->addTag('term_access');
$query->orderBy('t.weight');
$query->orderBy('t.name');
$tids = $query->execute()->fetchCol();
$children[$tid] = taxonomy_term_load_multiple($tids);
}

return isset($children[$tid]) ? $children[$tid] : array();
}
?>

Аватар пользователя leramulina leramulina 12 июля 2011 в 5:08

Вот этот выводит два уровня, но никак не могу понять, как сделать все уровни и настроить его на вывод только дочерних терминов.

<?php
$vid = 1;
$terms = taxonomy_get_tree($vid);
print "

    ";
    foreach ( $terms as $term ) {
    $tcount = taxonomy_term_count_nodes($term->tid);
    $children_terms = taxonomy_get_children($term->tid);
    if ($term->depth == 0) {
    print "
  • ";
    print l($term->name." (".$tcount.")",'taxonomy/term/'
    .$term->tid, array('title' => $tcount." posts in "
    .$term->name));
    if ($children_terms) {
    print "
      ";
      foreach ( $children_terms as $children_term ) {
      $t_children_count =
      taxonomy_term_count_nodes($children_term->tid);
      print "
    • ";
      print l($children_term->name." (".$t_children_count.")",
      'taxonomy/term/'.$children_term->tid, array('title' =>
      $t_children_count." posts in ".$children_term->name));
      print "
    • ";
      }/* end foreach children */
      print "

    ";
    }
    print "

  • ";
    }
    } /* end foreach */
    print "

";
?>