I want to display the block if the term is 21 (Chinese) and with "china" url path. I use this to control menu. If the term/tag is Chinese and the url path is china, the Chinese menu will show.
<?php/*
This snippet returns TRUE if the node we are
currently viewing is tagged with specific terms,
or has a particular URL path assigned to it
*/
$desired_terms = array(21); // put here the term IDs (tid). can be more terms like (21,22)$desired_path = 'china'; // put the URL path
// check taxonomy terms firstif ( arg(0) == 'node' and is_numeric(arg(1)) ) {
// Yes, we're viewing a node.
$node = node_load(arg(1));
foreach ($node->taxonomy as $term) {
if (in_array($term->tid, $desired_terms)) {
return TRUE;
}
}
}
// check url path next
// this should get the current drupal path, regardless of the clean url settingif ($_GET['q']) {
$my_drupal_path = $_GET['q'];
} else {
$my_drupal_path = substr($_SERVER['REQUEST_URI'], 1);
}
// this will convert a path like node/37 to clean/url/path, if one exists$my_path_alias = drupal_get_path_alias($my_drupal_path);
// check for the the url path component anywhere in the alias
// change this to $mypathalias == $desired_path to get an exact match insteadif (stristr($my_path_alias, $desired_path)) {
return TRUE;
}
// if all else fails, return falsereturn FALSE;?>See more: http://drupal.org/node/136029

0 comments:
Post a Comment