Есть такой хороший модуль Taxonomy_context, он выводит на странице родительских терминов подтермины.
Только вот одна проблема, у него нет счётчика материалов. Ну как обычно: Название подтермина, а в скобках числа материалов в этом подтермине.
Как это можно реализовать своими руками? Как добавить счётчик???
Комментарии
Из сниппета взять?
Может из сниппеета и пойдёт, только как его подключить?
В 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;
}
А вот сам сниппет:
$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);}
?>
Как правильно включить счётчик?
Как?
кто попможет? хотя бы дайте совет..
Актуально
Недавно столкнулся с такой-же задачей - посчитать количество нод в термине и вывести в списке терминов словаря, работая с модулем taxonomy_context.
Топик тут старый, но может еще кому будет актуален.
В моем случае это получилось так:
в taxonomy_context.module БЫЛО
if ($term->subterm) {
$output .= ' <h2 class="title">' . l($term->name, taxonomy_term_path($term)) . "</h2>\n";
}
в taxonomy_context.module СТАЛО
$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.
Почему-то многие вместо этой функции предлагают писать большой сниппет.