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

Link to comment
Share on other sites

  • 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.