3

I want to show the user picture on the search page. Currently only its show the user email or name, but I want to show the user profile picture.

How can I do that?

Note: the search page is about the user type, so when I search some users their picture should be displayed on the search result page.

3
  • Not able to understand which type of content you searching on search page
    – user52318
    Jan 15, 2016 at 10:42
  • user type when i am search some user its picture should be display on search result page Jan 15, 2016 at 10:46
  • midwesternmac.com/blogs/jeff-geerling/… go through this article hope so it may help you .
    – user52318
    Jan 15, 2016 at 13:41

1 Answer 1

3

Copy the file YOUR_SITE/modules/search/search-result.tpl.php to your theme and modify the code inside with this:

<?php
//obtaining the username
$username = explode('(', $title);
$username = trim($username[0]);
//getting the user object
$user = user_load_by_name($username);
?>
<li class="<?php print $classes; ?>"<?php print $attributes; ?>>
  <?php print render($title_prefix); ?>

  <?php 
  /*
   * The following line will print the user picture
   */
  print theme('user_picture', array('account' =>$user));
  ?>

  <h3 class="title"<?php print $title_attributes; ?>>
    <a href="<?php print $url; ?>"><?php print $title; ?></a>
  </h3>
  <?php print render($title_suffix); ?>
  <div class="search-snippet-info">
    <?php if ($snippet): ?>
      <p class="search-snippet"<?php print $content_attributes; ?>><?php print $snippet; ?></p>
    <?php endif; ?>
    <?php if ($info): ?>
      <p class="search-info"><?php print $info; ?></p>
    <?php endif; ?>
  </div>
</li>

This will be the output:

enter image description here

EDIT: If you want follow another way you can read this: How to access to the user info on the search page?

5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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