I have a view with exposed filters that allows users to search for other users on my site. The view displays users' profile pictures, and clicking a profile picture takes one to the relevant user's profile (put together using Panels).

I'd like to display a "Back to search results" link on the user profile whenever someone clicks on the link (picture) in the view and visits the profile. How might I go about doing this?

I'm using D7 with Panels and Views 3.

  • How did you solve hard-coded the view URI? – milkovsky Feb 27 '15 at 11:23

You can do this wih a new module modifying the user profile view.

// Implements hook_user_view().
function MY_MODULE_user_view($account, $view_mode, $langcode) {
  $account->content['link'] = array(
    '#weight' => -10,
    0 => array(
      '#markup' => '<a href="/VIEW_URI">Back to Search</a>',

Note: When adding a hook always remember to clear caches

If you also want to preserve the filter that the user has applied you can do so within your filter in the view by selecting 'remember the last selection' and selecting the roles that you want this for.

  • Thanks, but I wasn't able to get this to work. As I said in the question, I am overriding the user profile display in Panels, so perhaps the problem is Panels overriding the code in the custom module? – Patrick Kenny Nov 10 '12 at 2:29
  • Also, I can't hard-code the view URI; there are different ways to search so I need to link back to the view that the searching user was using. – Patrick Kenny Nov 10 '12 at 2:30
  • There is an option in views to preserve the filter (as mentioned above) so that should help with your second point. I havent used panels in a while and haven't used them much tbh views tends to do all I need. But if you can add a hard coded link to your user profile panels display and select that option on the filter in the 'search user' view then it should all work great. – James Nov 10 '12 at 19:51
  • If the preserve filters really wont cut it then you could use a jquery back button as explained here jquery4u.com/snippets/jquery-button-go-previous-page – James Nov 10 '12 at 20:11
  • This answer doesn't solve problem with "hard-coded the view URI" – milkovsky Feb 27 '15 at 11:23

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.