Счётчик для Taxonomy_context

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

Аватар пользователя Dec0der Dec0der 28 февраля 2008 в 16:01

Есть такой хороший модуль Taxonomy_context, он выводит на странице родительских терминов подтермины.
Только вот одна проблема, у него нет счётчика материалов. Ну как обычно: Название подтермина, а в скобках числа материалов в этом подтермине.

Как это можно реализовать своими руками? Как добавить счётчик???

Комментарии

Аватар пользователя Dec0der Dec0der 29 февраля 2008 в 0:38

Может из сниппеета и пойдёт, только как его подключить?

В taxonomy_context его нужно вставлять вроде куда-то сюда (это вывод терминов):

/**
 * Theme a term output.
 */

function theme_taxonomy_context_term($term) {
  $type = $term->subterm ? 'subterm' : 'term';
  $output = '';
  $output .= "<div class=\"$type-container\">\n";
  $output .= "  <div class=\"$type\">\n";
  if ($term->subterm) {
    $output .= "<img src=http://bira.by/misc/katalog.gif border=0/> " . l($term->name, taxonomy_term_path($term) . "/9");
  }
  if ($term->teaser) {
   $output .= '   <div class="teaser">' . $term->teaser . "</div>\n";
}
 else {
   $output .= '   <div class="description">' . $term->description . "</div>\n";
 }
 
 if ($term->links) {
   $output .= '   <div class="links">'. theme('links', $term->links) . "</div>\n";
 }
  $output .= "  </div>\n";
  $output .= "</div>\n";
  $output .= '<br>';
  return $output;
}

А вот сам сниппет:

<?php
$vid =2;  // номер словаря
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term ) {
    $count = "<span>(".db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)).")</span>";
    $items[] = l($term->name, "taxonomy/term/$term->tid") . " $count";
}
if ( count($items) ) {  print theme('item_list', $items);}
?>

Как правильно включить счётчик?

Аватар пользователя realizator@drupal.org realizator@drup... 8 февраля 2009 в 2:10

Недавно столкнулся с такой-же задачей - посчитать количество нод в термине и вывести в списке терминов словаря, работая с модулем taxonomy_context.
Топик тут старый, но может еще кому будет актуален.
В моем случае это получилось так:
в taxonomy_context.module БЫЛО

 
if ($term->subterm) {
    $output .= '   <h2 class="title">' . l($term->name, taxonomy_term_path($term)) . "</h2>\n";
  }

в taxonomy_context.module СТАЛО

if ($term->subterm) {
    $detok = taxonomy_term_count_nodes ($term->tid,'investigation');    
    $output .= '   <h2 class="title">' . l($term->name, taxonomy_term_path($term)) . " (".$detok.")</h2>\n";
  }

где "investigation" - это мой тип ноды.
Подробнее рекомендую посмотреть taxonomy_term_count_nodes.
Почему-то многие вместо этой функции предлагают писать большой сниппет.