Drupal 7 - Print User Picture on page.tpl.php
You are here
In your template.php file, add the following..
<?php function my_theme_preprocess_page (&$variables) { if ($variables['logged_in']) { $user = user_load($variables['user']->uid); if ($user->picture){ $variables['user_avatar'] = theme_image_style( array( 'style_name' => 'thumbnail', 'path' =>$user->picture->uri, 'attributes' => array( 'class' => 'avatar' ), 'width' => NULL, 'height' => NULL, ) ); } else{ $variables['user_avatar'] = '<a title="Profile" href=/user><img src="/sites/all/themes/my_theme/images/default.png" /></a>'; } } else { $variables['user_avatar'] = '<img src="/sites/all/themes/my_theme/images/default.png" />'; } }
Then go to your page.tpl.php and add the following to the section where you want the picture to appear:
<a title='Profile' href=/user><?php print $user_avatar; ?></a>
Category: