0

Trying to theme user pictures, in the following statement:

 print '<a href="' . $base_url . '/user/' . $friend_id . '" ><img src="' . _drupal_wall_user_profile_picture($friend_id) . '" width="32px"></a>';

How do I replace the "width="32px" by the "thumbnail" image style?

Thanks. :)

2 Answers 2

1

You need to (really should) use a render array. You can use theme_image_style:

// first, make a render array for your image, as a thumbnail...
$image_ra = array(
    '#theme' => 'image_style',
    '#path' => _drupal_wall_user_profile_picture($friend_id),
    '#alt' => 'Some alt value',
    '#title' => 'Some image title value',
    '#style' => 'thumbnail'
);


// now make your link render array...
$ra = array(
    '#theme' => 'link',
    '#text' => drupal_render($image_ra),
    '#path' => $base_url . '/user/' . $friend_id,
    '#options' => array(
        'html' => TRUE,      // this says the #text value is HTML markup
    )
);

// now you can render your image link into markup...
$image_markup = drupal_render($ra);

I took the long way to show you that you need to handle the image first, and then render it as #text in the link. I also did this to make the case that you really, really, really, really should use render arrays and stay away from writing the HTML. Let Drupal do that work. Just build a render array, pass it to drupal_render, and be done with it.

0

As per Drupal coding standards, you should not create links this way or render image this way. Use this code instead. For now I am using global (logged in) user, if you have to pass a friend user, load that user and follow the below approach.

global $user;
$file_user_picture = file_load($user->picture);
print l(theme('image_style', array(
  'path' => $file_user_picture->uri,
  'style_name' => 'thumbnail'
)), 'user/' . $user->uid, array('html' => TRUE,));

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.