I use this PHP code to show a block only on certain subdomains.(built using the Domain access module.)

global $_domain;
if ($_domain['domain_id'] == 0 || $_domain['domain_id'] == 28) {
  return TRUE;
}
return FALSE;

What happens is, with the above code the block is displayed on all pages while i want the block to be shown only on the front page of these subdomains.

What should i add to the above code to show the block only on the front page ?

Any help will be deeply appreciated.

-thank you

Comments

WorldFallz’s picture

just add && (drupal_is_front_page()) to your conditions.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

nirvanajyothi’s picture

So,will this be the right way to go?

global $_domain;
if ($_domain['domain_id'] == 0 || $_domain['domain_id'] == 28 && (drupal_is_front_page()) {
  return TRUE;
}
return FALSE;

-thank you

Medicine,Surgery ...and Drupal.

colin_e’s picture

I think you have your brackets in the wrong place.

You need to check you are on the front page ANDed with the result of "is this a valid domain?"

Try-

<?php
global $_domain;
if (($_domain['domain_id'] == 0 || $_domain['domain_id'] == 28) && drupal_is_front_page()) {
  return TRUE;
}
return FALSE;
?>

Regards: Colin

nirvanajyothi’s picture

It works well!!

Thank you WorldFallz & colin_e for the help.

Medicine,Surgery ...and Drupal.

nirvanajyothi’s picture

Can you please explain what should be added instead of && drupal_is_front_page

for displaying the block only on a particular node (Eg.www.example.com/content/node/300)

-thank you

Medicine,Surgery ...and Drupal.

WorldFallz’s picture

probably something like:

<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
  if (arg(1) == {your-nid} {
    return TRUE;
  }
}
return FALSE;
?>

Replace {your-nid} with the number of the node in question.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

nirvanajyothi’s picture

will try that out.

Thanks very much WorldFallz !

Medicine,Surgery ...and Drupal.