Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: Show/Hide Block On Forum

Submitted by on April 17, 2012 – 1:10 pmNo Comment

Here you will learn how to show or hide a block on a forum. The instructions include as How-To info for the whole forum (forum/*) as well for its pages in viewing or editing mode.

Solution

In a block settings, check “Show if PHP-code returns TRUE (PHP-mode, experts only).” and enter one of the following code pieces below.

DON’T SHOW a block on forum PAGES:
*A block will be visible on pages with ‘forum/*’ URL

$result=true;
if ((arg(0) == ‘node’) && is_numeric(arg(1))) {
$node = node_load(arg(1));
if ( $node->type == “forum” )  $result=false;
}
return $result;

This code returns TRUE only if ‘forum’ node isn’t viewed this time. So a block is shown always except ‘forum’ node is currently opened.

Show a block ONLY on forum PAGES:
*Shows a block only on a forum pages (this includes viewing and editing of a forum nodes)

if (arg(0) == ‘forum’)   return TRUE;
if (arg(0) == ‘node’ && is_numeric(arg(1))) {
$result= db_fetch_object(db_query(“SELECT n.type FROM {node} AS n WHERE n.nid=%d LIMIT 1″, arg(1)));
if ($result->type == ‘forum’)     return TRUE;
}
return FALSE;

DON’T SHOW a block everywhere on a forum
*A block will be hide on a whole forum (this includes viewing and editing of a forum nodes)

if (arg(0)==’node’ && is_numeric(arg(1))){
$result= db_fetch_object(db_query(“SELECT n.type FROM {node} AS n WHERE n.nid=%d LIMIT 1″, arg(1)));
if ($result->type == ‘forum’)     return FALSE;
} elseif (arg(0)==’forum’)  return FALSE;
return TRUE;

DON’T show a block when viewing or editing a topic only:

if (arg(0)  ==  ‘node’ && arg(1)){
$result= db_fetch_object(db_query(“SELECT n.type FROM {node} AS n WHERE n.nid=%d LIMIT 1″, arg(1)));
return ($result->type != ‘forum’);
}

Showing a block when viewing or editing a ‘forum’ node is your homework =)

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.