Skip to main content
ComputerMinds

Making a drupal views block title link back to the view

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,…

Steven Jones · 1 min read

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

<code class="language-php hljs">
  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;
      }
    }
  }
</code>

[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)

Written by

Steven Jones

Meet the team