Skip to main content

Making a drupal views block title link back to the view

An article from ComputerMinds - Building with Drupal in the UK since 2005
24th Jan 2009

Steven Jones

Senior Developer
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

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)

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.