Views: how to override a linked "Content: Title" field's href programmatically? I would like to override a Views-generated block's "Content: Title" field's href path (linked to nodes with "Link this field to the original piece of content") to append a query string ($_GET['page']).

An example:

this is the generated link:

&lt;a href="/my_drupal_subdir/hu/my_test_alias/blabla" class="views ..."&gt;Blabla&lt;/a&gt;


I would like this one:

&lt;a href="/my_drupal_subdir/hu/my_test_alias/blabla?page=0,0,2" class="views ..."&gt;Blabla&lt;/a&gt;


I would like to override the path and append a query string before it gets rendered as an HTML-link (&lt;a&gt;).

How should I do this? I think Views uses views_handler_field_node::render_link() and views_handler_field::render_as_link() which calls function l() or sg. like that which should be overridden. Of course, overriding theme_link() for modifying ALL the links is not a good way.



Here's an export of the simplest possible block view for Articles with pager id 3; the titles are linked:
http://pastebin.com/tmq0kZwT
I want to override the title links of this list to append a query string (to remember the actual pager when clicking on a node).
Here is the solution:

Put the following code to your theme's template.php file, and substitute MYTHEME with your own theme's name (or you can even put it in your module's file, and substitute MYTHEME with your module's machine name):

&lt;?php

/**
 * Implements template_preprocess_views_view_field()
 * @see http://api.drupal.org/api/views/theme!theme.inc/function/template_preprocess_views_view_field/7
 * Process a single field within a view.
 * This preprocess function isn't normally run, as a function is used by default, for performance. However, by creating a template, this preprocess should get picked up.
 */
// /* -- Comment out this line if you want to use this function
function MYTHEME_preprocess_views_view_field(&amp;$vars) {
  // $vars['output'] = $vars['field']-&gt;advanced_render($vars['row']);

  // @see http://drupal.org/node/939462#comment-4476264
  if (isset($vars['view']-&gt;name)) {
    $function = 'MYTHEME_preprocess_views_view_field__' . $vars['view']-&gt;name . '__' . $vars['view']-&gt;current_display;

    if (function_exists($function)) {
      $function($vars);
      // we can return to only use the specific preprocess function (it matters if there are more codes below in this function)...
      return;
    }
  }
}
// */


/**
 * Implements template_views_view_field__VIEW_MACHINE_NAME__DISPLAY_MACHINE_NAME()
 * @see template_views_view_field()
 * @see MYTHEME_views_view_field()
 */
// /* -- Comment out this line if you want to use this function
function MYTHEME_preprocess_views_view_field__block_of_articles__block(&amp;$vars) {
  // $vars['output'] = $vars['field']-&gt;advanced_render($vars['row']);

  if (isset($vars['row']-&gt;nid, $vars['row']-&gt;node_title)) {
    $path    = drupal_get_path_alias('node/' . $vars['row']-&gt;nid);
    $options = array();
    if (isset($_GET['page'])) {
      $options['query'] = array(
        'page' =&gt; $_GET['page']
      );
    }

    $vars['output'] = l($vars['row']-&gt;node_title, $path, $options);
  }
}
// */


Don't forget to clear your cache!
This should only be done in cases when it's really needed: for example when an Article listing block (like this really simple one which you can import: http://pastebin.com/tmq0kZwT) is also displayed next to the article nodes, and we want the current pager position to be "remembered".