Forums

If Statement Help (If user does not have gravatar) (6 posts)

  1. xdesi
    Member
    Posted 3 years ago #

    Hi,

    How would I say

    IF user has gravatar then fair enough display it
    ELSEIF not then do blah blah blah??

  2. moshu
    Member
    Posted 3 years ago #

    I have something like this:

    <?php if(function_exists('get_avatar')){
      echo get_avatar($comment, '32', $default=identicon);
    } ?>

    (see it in action)

    Regarding the "identicon" see:
    http://en.blog.wordpress.com/2008/05/04/default-avatars/

  3. Otto
    Tech Ninja
    Posted 3 years ago #

    Short answer: You don't. There is no easy way to tell if a user has a gravatar or not. The way it works is that it sticks the correct image code into the page and lets the gravatar server either serve up the gravatar or the default image.

  4. xdesi
    Member
    Posted 3 years ago #

    OK, it's just I have the users select from a range of avatars, and was wondering if I could display a Gravatar if they have one, if not display the one they selected on the comment form.

    I'll just go for one or the other.

  5. Otto
    Tech Ninja
    Posted 3 years ago #

    Oh. Yeah, you can do that. The third parameter to the get_avatar function is a "default" setting. If they have no avatar, then that one displays.

    Like this:
    get_avatar( $comment, 96, 'http://example.com/avatar.gif' );

  6. xdesi
    Member
    Posted 3 years ago #

    Sorry for the delay, I understand now.

    Just one problem with my PHP skills really, how do i go about inserting a PHP statement within the default location, for example:

    $default = 'http://www.mysite.com/print $comment->extra_avatar;.jpg' );

    Obviously the part in bold retrieves the image name, but how do i execute this correctly? I guess I need to escape the quotes somehow?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags