News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

how to show the users avatar on a diffrent page.

Started by Regashi, February 17, 2008, 08:44:07 AM

Previous topic - Next topic

Regashi

hi i would like to know how to show the users avatar when he loggs in .

please may somebody help me out here.

Kindred

you mean on a non-forum page?

load SSI.php and then echo the avatar

<?php
require_once('path/to/SSI.php')

   if (!empty($context['user']['avatar']))
      echo $context['user']['avatar']['image'];
?>
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

virtualxtc

This code doesnt seem to work for me.
It says unexpected IF
Any ideas?

Kindred

try this...

<?php
require_once('path/to/SSI.php')

   if (!empty($user_info['avatar']['url']))
      echo $user_info['avatar']['url'];
?>
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

virtualxtc

Still get this error msg...
Parse error: syntax error, unexpected T_IF in /home/blah/public_html/index.php on line 32

Kender


<?php
require_once('path/to/SSI.php');

   if (!empty(
$user_info['avatar']['url']))
      echo 
$user_info['avatar']['url'];
?>


@Kindred: you didnt put the semicolon after the require

also, you need to be sure the path/to/ssi.php is the actual full path
see the ssi_examples.php page on your forum for a refrence
http://chucknorris2012.com  Avoid a roundhouse kick to the head!  Sign the petition

virtualxtc

Im not getting any errors on anything but the avatar isn't showing up.
Do i have to specify anything other than the path to SSI?

Code I'm Using...

<?php
require_once('/home/blah/public_html/forums/SSI.php');
   if (!empty(
$user_info['avatar']['url']))
         echo 
$user_info['avatar']['url'];
?>


Dragooon

Try this
<?php
global $user_info;
require_once(
'/home/blah/public_html/forums/SSI.php');
   if (!empty(
$user_info['avatar']['image']))
         echo 
$user_info['avatar']['image'];
?>

Kender

this is the code taken from my index.template of the theme im using currently, it should give you what you need in the ssi

<?php
require_once('/home/blah/public_html/forums/SSI.php');

if (!empty(
$context['user']['avatar']))
{
if(empty($settings['top_avatar_resize']))
{
$context['user']['avatar']['image'] = strtr($context['user']['avatar']['image'], array("class=\"avatar\"" => "class=\"avatar_t\""));
}
echo '<div style="padding: 0 10px 0 10px;  float: left;">'$context['user']['avatar']['image'], '<div class="avatar_frame"></div></div>';
?>
http://chucknorris2012.com  Avoid a roundhouse kick to the head!  Sign the petition

virtualxtc

Both not working :(
The first one doesn't error but doesn't display an avatar.
The 2nd one gives me an error.

Kender

you may need to global context

require_once......
global $context;
if .....
http://chucknorris2012.com  Avoid a roundhouse kick to the head!  Sign the petition

Dragooon

OK I can't find a cleaner way don't know why

<?php
global $ID_MEMBER$memberContest;
loadMemberData(array($ID_MEMBER));
loadMemberContext($ID_MEMBER);
$member $memberContext[$ID_MEMBER];
if(!empty(
$member['avatar']['image']))
  echo 
$member['avatar']['image'];
?>


Its untested though.

Kindred

Quote from: Kender on March 28, 2008, 02:28:34 AM
@Kindred: you didnt put the semicolon after the require

'DOH!   yup, I did...   and i just realized something else...

No need for that mess, Dragoon.


<?php
require_once('path/to/SSI.php');

   if (!empty(
$user_info['avatar']['url']))
      echo 
'<img src="' $user_info['avatar']['url'] . '" alt="Avatar" />';
?>

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Dragooon

@Kindred, that won't work if a user has selected from the server or has uploaded his/her own image.

Kindred

you're right... and I was right the first time...


<?php
require_once('path/to/SSI.php');

   if (!empty(
$context['user']['avatar']))
      echo 
$context['user']['avatar']['image'];
?>

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Dragooon


virtualxtc

Quote from: Kindred on March 28, 2008, 09:02:24 AM
you're right... and I was right the first time...


<?php
require_once('path/to/SSI.php');

   if (!empty(
$context['user']['avatar']))
      echo 
$context['user']['avatar']['image'];
?>



WOOOOOOO!!!
Cheers Mate!
Works like a charm.

Advertisement: