Created
September 10, 2012 12:31
-
-
Save grammaticof/3690660 to your computer and use it in GitHub Desktop.
Drupal - taxonomy term base block view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//code snippet for causing block to show based on a node's taxonomy term | |
$make_block_visible = FALSE; | |
$term_id_to_trigger_show_block = 19; // replace '19' your term id. | |
if ((arg(0) == 'node') && is_numeric(arg(1))) { | |
$values = array( | |
':nid' => arg(1), | |
':tid' => $term_id_to_trigger_show_block, | |
); | |
$result = db_query("SELECT nid FROM {taxonomy_index} WHERE nid=:nid AND tid=:tid", $values)->rowCount(); | |
if ($result) | |
$make_block_visible = TRUE; | |
} | |
// The following code will cause block to show on the designated term's built-in "view" page such as: | |
// example.com/taxonomy/term/19 | |
if ((arg(0) == 'taxonomy') && (arg(1) == 'term') && (arg(2) == $term_id_to_trigger_show_block)) { | |
$make_block_visible = TRUE; | |
} | |
return $make_block_visible; | |
?> | |
<?php | |
//code snippet for causing block to NOT-show based on a node's taxonomy term | |
$make_block_visible = FALSE; | |
$term_id_to_trigger_show_block = 19; // replace '19' your term id. | |
if ((arg(0) == 'node') && is_numeric(arg(1))) { | |
$values = array( | |
':nid' => arg(1), | |
':tid' => $term_id_to_trigger_show_block, | |
); | |
$result = db_query("SELECT nid FROM {taxonomy_index} WHERE nid=:nid AND tid=:tid", $values)->rowCount(); | |
if (!$result) | |
$make_block_visible = TRUE; | |
} | |
// The following code will cause block to NOT-show on the designated term's built-in "view" page such as: | |
// example.com/taxonomy/term/19 but in all the other cases | |
if ((arg(0) == 'taxonomy') && (arg(1) == 'term') && (arg(2) != $term_id_to_trigger_show_block)) { | |
$make_block_visible = TRUE; | |
} | |
return $make_block_visible; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment