Displaying block on Front Page ONLY

I had a strange problem today. I wanted to show a block on homepage only. So I went to the Block and added "" and clicked the box "Show only on listed pages". You would think this should work. But when your website has "node" as front page and if you have 10 pages of Nodes, the block will show on all 10 pages and not just the home page

This is a weird problem, I tried many combinations, until I figured out that you have to put the following PHP Code and select "Show only if PHP code returns TRUE"


<?php
$match = FALSE;
$url = request_uri();

if (drupal_is_front_page()) {
$match = TRUE;
}
if ($match and (strpos($url, "page"))) {
$match = FALSE;
}
return $match;
?>

So how does this code work. First part is simple , if its drupal front page then it returns TRUE, however if there is a string "page" in the URL, then it will return false and the block will not show up.

So you can basically analyze you URL and change the string "page" to anything. You can even put the string "?", indicating that if there is a ? in the URL the Block should not show up.

This way you will see that that block will only show up on home page. Nice little trick.

How-To: