fbpx Making a drupal views block title link back to the view | ComputerMinds Skip to main content

Making a drupal views block title link back to the view

24th Jan 2009

Steven Jones

Senior Developer

One for the small but handy category this. The standard "more" link the views module adds to it's blocks has no place on a modern accessible website, you really need a more verbose link in there. One solution has always been to add a bit of footer or header text into the block, but it's a little tedious - and clients always find views hard to edit.

This simple solution will turn the block title into a link to the view, it goes into your template.php _phptemplate_variables function


  if ($hook=='block'){
    $block = $vars['block'];
    if ($block->module == 'views'){
      $view = views_get_view($block->delta);
      if ($view->page && $view->url && $block->subject){
        $link =  l($block->subject,$view->url,array(),null,null,false,true);
        $vars['block']->subject = $link;
      }
    }
  }

[EDIT] - as per comments below, the above is Drupal 5.x only - the principle could be applied in 6.x using a preprocess hook (either in your template.php or in a simple module)