Jump to content

Show Drupal block at a certain time of day on certain pages


alwoodman

Recommended Posts

Hi

 

I am trying to get drupal to only show a block during certain times of the day and only on a specific URI but it keeps showing up on other pages so the

 

 substr($_SERVER["REQUEST_URI"], 0) == "/folder/mypage")

 

must be the issue i assume?

 

<?php
$time = (int) date('Gi');
return (($time < 600 && $time >= 0000) || ($time > 1630 && $time <= 2359) && substr($_SERVER["REQUEST_URI"], 0) == "/folder/mypage");
?>

<?php
$time = (int) date('Gi');
return (($time > 600 && $time < 1630)) && ($_SERVER["REQUEST_URI"] == "/folder/mypage"));
?>

 

thanks

 

Lee

  • 2 weeks later...

First off - how are you generating your block - are you creating it through the 'create block' admin interfaced, or are you creating it in a module?

 

Next, you don't use $_SERVER['REQUEST_URI'] in Drupal. This will give you innacurate results, as Drupal paths are all virtual. As such you would use the following:

 

if($_GET['q'] == "folder/mypage");

 

$_GET['q'] contains the path in Drupal in the non-rewritten version of the URL. note that it doesn't use a leading forward slash.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.