0

I am setting up a block in Drupal 7 to "show block on specific pages" through PHP.

What I want is that if it's a Front page and there is a GET (listed) variable, only then it shows the block otherwise not.

Hence, the block would only be shown, if the url is www.site.com/?listed=true

I tried this, but it doesn't work:-

<?php
if ( (drupal_is_front_page()) && ( !empty($_GET['listed'])  ) {
  return true;
}
?>

any idea?

2 Answers 2

1

You missed a closing bracket. Try this:

<?php
if (drupal_is_front_page() && !empty($_GET['listed'])) {
  return TRUE;
}
?>

or

<?php
if (drupal_is_front_page() && isset($_GET['listed'])) {
  return TRUE;
}
?>
1

I would suggest to look at Context module. It gives you lot of options to configure.

In your case you can add a new context and put two conditions

  1. Path = <front>
  2. Query String : listed=true

then add a reaction to display the block you want. Its simple.

Not the answer you're looking for? Browse other questions tagged or ask your own question.