How can I show a block on term pages if no nodes are tagged with that term an开发者_开发知识库d also there are no child terms?
Im using Drupal 6. Thanks
Tricky one but you could use custom PHP code for your block display, something like this (assuming Drupal 6 here):
if (strstr($_GET['q'], 'taxonomy/term/')) {
$parts = explode('/', $_GET['q']);
$term = taxonomy_get_term($parts(2));
if ($term && $term->tid) {
$node_count = db_result(db_query('SELECT COUNT(nid) FROM {term_node} WHERE tid = %d', $term->tid));
if ($node_count == 0) {
return FALSE;
}
if (count(taxonomy_get_children($term->tid)) == 0) {
return FALSE;
}
return TRUE;
}
}
return TRUE;
And for Drupal 7:
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric($arg(2))) {
$term = taxonomy_term_load(arg(2));
if ($term && $term->tid) {
if (db_query('SELECT COUNT(nid) FROM {taxonomy_index} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField() == 0) {
return FALSE;
}
if (count(taxonomy_get_children($term->tid)) == 0) {
return FALSE;
}
return TRUE;
}
}
return TRUE;
精彩评论