3

I have a block I want to show in specific content types and some URLs.

I tried adding the following code.

  $match = FALSE;
  // block is visible on the content types entered here
  $types = array('story' => 1, 'page' => 1);
  $url = request_uri();
  if ((arg(0) == 'node') && is_numeric(arg(1))) {
    $node = node_load(arg(1));
    $match = isset($types[$node->type]);
  }
  // block is invisible on URLs entered here
  if (strpos($url, "edit")) {
    $match = TRUE;
  }
  // copy paste these for additional URLs
   if (strpos($url, "taxonomy/term/8")) {
    $match = TRUE;
  }
  return $match;

Is it possible to use wildcard or something to include all the child in this taxonomy, instead of using taxonomy/term/8?

2
  • all children of taxonomy specified term (in here 8 )?
    – Yuseferi
    Commented Jul 20, 2014 at 12:55
  • 7 is parent taxonomy and 8 is child . i want to show it in all children from 7
    – user23811
    Commented Jul 20, 2014 at 13:21

1 Answer 1

1

If you want to check all children of specified term below code can help you

first load all children of it ,then check its term ids one by one

$tids=array_keys(taxonomy_get_children(8));
foreach($tids as $tid)
 if (strpos($url, "taxonomy/term/".$tid)) {
    $match = TRUE;
    break;
  }
7
  • 1
    also I have better solutions,but it is simple and without any big changes in your previous code.
    – Yuseferi
    Commented Jul 20, 2014 at 13:02
  • should i put this code in my code ?
    – user23811
    Commented Jul 20, 2014 at 13:12
  • i added this instead of my code . Updated my question
    – user23811
    Commented Jul 20, 2014 at 13:20
  • @Soheil Then what you want now?
    – Yuseferi
    Commented Jul 20, 2014 at 13:24
  • it's not working :) .the block doesn't show up
    – user23811
    Commented Jul 20, 2014 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.