0

Drupal 6, Views 2.

I would like the "View" link to point somewhere completely different than it normally does.

I've implemented hook_views_pre_render() and dug around in the $view object, but I can't seem to find the path in there.

How can I change the "View" link?

2
  • Are you talking about the links that's possibly created on the view (like pagers) or the url that the user uses to get the view displayed in the first place?
    – googletorp
    Feb 29 '12 at 15:16
  • I'm not entirely sure which links you mean either ;) Views has a "Create more link" option, which generates a link to view "More content" of the current type.
    – Letharion
    Feb 29 '12 at 15:20
3

If all else fails, just edit the views template. Go into the views theming information and select the template and edit the more link for it. It would be named along the lines of views-view--MYVIEWNAME--MYVIEWDISPLAYNAME.tpl.php and inside you can edit the more link area in the template. (There is also a more template you can modify but I've not done it that way before)

<div class = "more-link">' .
l(
  t('See more'),
  'internal/path/' . $view->args[0],
  array('options' => array('HTML' => TRUE))
) .
'</div>';
9
  • Wouldn't this require me to manipulate already rendered HTML? That gives me an idea though...
    – Letharion
    Mar 1 '12 at 17:24
  • nope, the template is what generates the html
    – Jimajamma
    Mar 1 '12 at 17:37
  • The more link is already rendered at that point, and simply available as a $more variable, which contains HTML. Or am I being slow now? Copied from a template: <?php if ($more): print $more; endif; ?>. I found a more-link.tpl.php as well, but there doesn't appear to be a $view in there, so I can't control it without making it theme global.
    – Letharion
    Mar 1 '12 at 19:16
  • Instead of <?php if ($more): print $more; endif; ?> put in <?php print l('GO HERE','http://www.foo.com'); ?> or whatever you want or grab any values you want out of $row etc.
    – Jimajamma
    Mar 1 '12 at 21:20
  • So, thus far, I was just being stupid >_<. However, $rows, has also already been rendered at this stage, meaning I would be forced to reverse lookup the term-id I'm looking for from a path-auto alias.
    – Letharion
    Mar 3 '12 at 11:39
6

I used this method (views 3.x):

 <?php
 // get the $view object somehow and alter the display_handler options
 // see views_plugin_display.inc ~ render_more_link() method
 $view->display_handler->set_option('link_display', 'custom_url');
 $view->display_handler->set_option('link_url', 'node/!1/somewhere');
2
  • 2
    I used this in hook_views_pre_render(). Apr 28 '15 at 5:08
  • Yes, it can be used anywhere a $view is available, eg from views_get_view("view_name")
    – lcapra
    Feb 6 '16 at 8:11
1

Although views templates are very powerful, if all you need is a link, you could just put one in the footer field and use the same css class views does for read more links.

1
  • Unfortunately I can't use the footer field, as I need tokens, which is not supported in Views 2.
    – Letharion
    Mar 1 '12 at 17:18
1

Just building on what was mentioned above (I didn't feel comfortable just editing the original answer).

For Views 3: You can do the following....

  • Add a More link with custom text
  • Create your views tpl file using hte 'Display' style
  • Within the views tpl file change the More code to:

    if ($more): 
        print str_replace('/front', '/latest-news', $more);
    endif;
    

Note: You will need to add the proper php code around each line (I couldn't figure out how to do that in the editor :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.