Jou*_*key 4 drupal image avatar
我在这里使用此代码在节点上显示userpicture:
<?php
$user_load = user_load($node->uid);
$imgtag = theme('imagecache', 'avatar_node', $user_load->picture, $user_load->name, $user_load->name);
$attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
print l($imgtag, 'u/'.$user_load->name, $attributes);
?>
Run Code Online (Sandbox Code Playgroud)
这很好用,除非用户没有图片,在这种情况下它看起来很奇怪.
如果用户没有图片,如何加载默认图片.我不相信我能在这个区块中访问$ picture.
提前致谢.
$user_load = user_load($node->uid);
$picture = $user_load->picture ? $user_load->picture : variable_get('user_picture_default', ''); //
$imgtag = theme('imagecache', 'avatar_node', $picture, $user_load->name, $user_load->name);
$attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
print l($imgtag, 'u/'.$user_load->name, $attributes);
Run Code Online (Sandbox Code Playgroud)
如果将默认图片复制到文件目录,可以通过http://api.drupal.org/api/function/file_directory_path/6确定