Sam
Sam

Reputation: 111

Display .PHP block on /blog but not inner blog pages

I have a block which is showing on both my main blog page (/blog) and the individual blog pages themselves.

I'd like to have the block continue to show on the main blog page but not on individual blog pages.

For example the block should show on - this page but not this page.

The blocks .PHP is as follows:

<?php 
$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
$link = url($path, array('absolute' => TRUE));
$findme   = 'blog';
$pos = strpos($link, $findme);
if ($pos !== false) {
  RETURN TRUE;
}
$node = node_load(arg(1));
if($node->type == 'blog') {
  return TRUE;
}
?>

Upvotes: 0

Views: 57

Answers (2)

Anthony Leach
Anthony Leach

Reputation: 1993

Instead of using the php filter option go to the configuration page for the given block.

Under visibility settings, within the 'pages' fieldset. Select the 'Only on the listed pages'. In the textarea underneath enter the path of the blog, in your example 'blog'. If you wanted this block to appear only on child pages, you could enter 'blog/*' instead.

Alternatively, if this is a programatically created block, within the implementation of hook_block_info. Add the following keys to the block array.

'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => 'blog',

Example

function hook_block_info() {
  $blocks = array();

  $blocks['example_block'] = array(
    'info' => t('Example block'),
    'status' => 1,
    'region' => 'content',
    'visibility' => BLOCK_VISIBILITY_LISTED,
    'pages' => 'blog',
    'cache' => DRUPAL_CACHE_GLOBAL,
    'weight' => 3,
  );
}

Upvotes: 0

Att3t
Att3t

Reputation: 466

go to /admin/structure/blocks, search for the name of the block , configure , in the Pages tab , choose "Only the listed pages" , then in the text area write the title of the main blog page

Upvotes: 1

Related Questions