0

I've added this code to show user picture under own post and it works perfectly but when i logged out , i cant see user picture !!??

<div class="user-pic">

            <?php
            $user = user_load($user->uid);
            if($user->picture){
                print theme_image_style(
                    array(
                        'style_name' => 'user-pic',
                        'path' => $user->picture->uri,
                        'attributes' => array(
                            'class' => 'avatar'
                        )
                    )
                );
            }
            ?>
        </div>  

Any advice ?

  • who will be the user when you will log out ?? you are displaying a user picture so it shows the picture of the logged in user. when you logged out the user becomes anonymous – Fahad Aug 26 '14 at 19:20
  • i want to show it to everyone and it's public @Fahad – Soheil Aug 26 '14 at 19:29
  • In that case you need to get the $account and not the $user – J. Reynolds Aug 27 '14 at 4:34
  • Just to elaborate. You are getting the uid of the currently logged in user, when you should get it of the account attached to the resource you are viewing. It is usually attached to the resource so you won;t have to load it. – J. Reynolds Aug 27 '14 at 4:46
  • I doubt this code will work without 'global $user', also it is not a good idea to use global variable $user to store data. – nit3ch Aug 27 '14 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.