Drupal - Display Content on Front Page Only

Tags:

You may want to display a block of content only on the front page of your Drupal powered website. A fairly simple thing to do just select the "Show on only the listed pages" box and put <front> into "Pages:" section.

Yes that will show the block on the front page, but it will also show the block on all of the paginated pages as well.

If you don't want the block to show on the paginated pages you can do the following:

Select "Show if the following PHP code returns TRUE (PHP-mode, experts only)" and put the following code into the "Pages:" section:

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

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

This code assumes that you have the front page of your website configured as "node" if you had it configured to something different such as "front" you would need to modify the code as per the below example.

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

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

This has been tested with both Drupal 5 and Drupal 6.

Hi, it works good on my

Hi, it works good on my drupal 5 site.
Do you know how to add block only on
http://www.somesite.com/node?page=5

I already tried many ways and I'm out of idea.

Thanks

Submitted by Sylvester (not verified) on Fri, 2012-01-20 23:11.

Front page

Better code:

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

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

Probably not perfect but treats page=0 or just node as front page.

Submitted by Joyce Melton (not verified) on Tue, 2012-02-21 06:46.