Showing a block in specific content types and URLs

by Soheil   Last Updated January 09, 2018 12:07 PM

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?

Tags : views blocks


Answers 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;
  }
zhilevan
zhilevan
July 20, 2014 13:01 PM

Related Questions



Drupal 8 views - Message contextual filtering

Updated July 11, 2018 20:07 PM


In the snatch face a 177 dealers smart

Updated June 13, 2015 08:03 AM

Website consuming more memory

Updated August 26, 2016 08:04 AM