Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Ok so i have added a custom field inside of the WordPress edit profile field where a contributor and above can add a custom image if they do not use gravatar. Now i am trying to write a if else statement and this is what i have

<?
    $hasauthorpic = (the_author_meta('author_pic'));
    if (function_exists('get_avatar')) { echo get_avatar( get_the_author_email(), '80' );}
    else {echo '?><img class="avatar avatar-80 photo"><? $hasauthorpic ?></img><? ';}
?>

What i want to try and do is if the user does have a gravatar use it unless they have specified a link to there profile pic. Or have the author_pic become higher priority even if user has gravatar.

EDIT:

<?
$authorpic = the_author_meta('author_pic');
$gravatar = get_avatar( get_the_author_email(), '80' );
    if ($authorpic); 
    elseif (function_exists('get_avatar')) 
            echo ($gravatar); 
?>

OK so i tried the code below and that did not quite work. Maybe because i am putting this into a single-whatever.php file. The above is what i have managed to get but the only problem is when it shows it shows both the avatar and author pic link so i know i still need to add the <img> tags but that will be easy later. The one thing i did read is that your cant put a true on the_author_meta so i need help.

If you can come up with a code to hook into the gravatar stuff then ill take it. In other words if you have a code that i can place in my functions.php file thatll work to i and i would prefer that. the field name is author_pic

UPDATE: This is my final write up with the provided code from below

<?php
$authorpic = get_the_author_meta('author_pic');
$imgtagbeg = ('<img style="height:80px; width:80px" src="');
$imgtagend = ('"/>');
if ($authorpic)
    echo $imgtagbeg,$authorpic,$imgtagend; 
else
    echo get_avatar( get_the_author_email(), '80' ); 
?>
share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

You need to use get_the_author_meta() instead of the_author_meta()

<?php
$authorpic = get_the_author_meta('author_pic');
if ($authorpic)
    echo $authorpic; 
else
    echo get_avatar( get_the_author_email(), '80' ); 
?>
share|improve this answer
    
can you explain how the get_the_author_meta will show the image when that is meant for displaying none –  xLRDxREVENGEx May 22 '11 at 5:47
2  
echo $authorpic; will echo whatever you are storing in the author_pic author meta field. –  aaronwaggs May 22 '11 at 5:55
    
I did use this but changed the code a bit. Ill post my final solution above in my question but mark your solution. –  xLRDxREVENGEx May 23 '11 at 2:38
add comment

Your if will always return true and bypass your custom author pic.

Run the if on the custom field. If it returns true then add a filter to get_avatar that uses the custom field author pic.

if ( the_author_meta('author_pic') ) {
add_filter( 'get_avatar', 'your_custom_author_pic_function' );
}
share|improve this answer
    
Makes sense. Still Learning. –  xLRDxREVENGEx May 22 '11 at 2:46
    
Ok so what about adding an <img> tag for the author pic where do i insert this –  xLRDxREVENGEx May 22 '11 at 3:20
    
In your custom function. Take a look at this question for more details on filtering get_avatar. –  Chris_O May 22 '11 at 3:31
    
ok but this is not a custom function unless it would work better that way. I simply have it in a template page –  xLRDxREVENGEx May 22 '11 at 3:40
    
Ok so i updated my original question maybe you can take a look at it –  xLRDxREVENGEx May 22 '11 at 4:22
add comment

There is a sweet new plugin I recently discovered called Simple Local Avatars that will do exactly what you ask. Check it out!

share|improve this answer
    
seen it. not what i want i do not want my users uploading pics. and i would prefer a hard code solution –  xLRDxREVENGEx May 22 '11 at 14:38
add comment

If I understand correct, you don't want people to upload a custom avatar, but you do want people to be able to link to a custom avatar? (and, if not, a default avatar or gravatar kicks in) If that's the case, this article will probably suit your needs http://www.billerickson.net/wordpress-custom-avatar/

share|improve this answer
    
i have already got this working. as well the user will not be able to link to any image. I use my own url and the server checks for the image based of of there username –  xLRDxREVENGEx May 30 '11 at 22:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.