Question: How can I add the member avatars to my comments
Answer:
{if avatar}
<img class="avatar" src="{avatar_url}"
width="{avatar_width}" height="{avatar_height}" alt="{name}" title="{name}" />
{/if}
Linebreaks inserted, make sure you remove them first. =)
Question: How can I display a default avatar if the comment author doesn’t have one uploaded
Answer:
{if avatar_filename == ''}
<img >http://www.yourdomain.com/your_default_avatar.gif</nowiki>" width="50" height="50" alt="Avatar for {name}" class="avatar" />
{/if}
{if avatar}
<img src="{avatar_url}" width="{avatar_width}" height="{avatar_height}" alt="Avatar for {name}" class="avatar" />
{/if}
To display a Gravatar as the default, using the Philip Zaengle update of the EEGravatar plugin:
{if avatar_filename == ''}
<img class="avatar" src="{exp:gravatar email='{email}' size='90' rating='PG' default='{site_url}images/avatars/uploads/no_avatar.gif'}" width="90" height="90" alt="{name}" title="{name}" />
[/if]
To display a member avatar, a member Gravatar, or a default, automatically according to what is available, again with latest EE1.6 and EE2 compatible EEGravatar, you can use:
{if avatar}
<img class="avatar" src="{avatar_url}" width="{avatar_width}" height="{avatar_height}" alt="{name}" title="{name}" />
{if:else}
<img class="avatar" src="{exp:gravatar email='{email}' size='90' rating='PG' default='{site_url}images/avatars/uploads/no_avatar.gif'}" width="90" height="90" alt="{name}" title="{name}" />
{/if}
You can supply an alternate avatar at the path location named as default, rather than the one named here that comes (always?) with the EE install, if you like.
This code will prefer a member avatar, if they have specifically uploaded one. If they haven’t, then any gravatar associated with their member email will be used. If no gravatar is available for the email, then the default no_avatar.gif (or whatever default image you pathed and provided) will appear.
Note that {if avatar} doesn’t function as you would expect. It will be false even if avatars are turned on in Member Preferences, if there’s not an uploaded member avatar available (or if not signed in as a member). You would have to use a global variable you make yourself to gain proper control, if you want to turn off avatar presentation entirely.
Be sure you have the comment entries loop outside the channel entries loop, or subtle things won’t work properly—like {email}. If {email} isn’t present, for example, then the gravatar can’t be found.
Similarly the {exp:comment:form} content goes third, outside both.
Having the exp:gravatar code within the comment:entries loop is fine - that’s where it’s intended to work.
