homepage Welcome to WebmasterWorld Guest from 54.204.77.26
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

    
how to return false if user field is empty
using script in custom_functions.php for wordpress thesis theme
AlexB77




msg:4535972
 6:26 pm on Jan 14, 2013 (gmt 0)

I have a script that I have somehow managed to create (since my knowledge of php is very limited) that basically places author's profile (image, bio, and links to social media) on to authors archive page with all the posts by same author.

the problem with this script is it returns empty href's and src's in the div's if inputs in the authors profile are empty. I understand the reason why it does this, but I do not know how to correct it.

the second problem is if author set up a custom image link that my script returns that image, but what also like to do in case if input for that link is empty is to return an avatar.

Here is my script

/***********************************************************
******************* Custom Author Page *********************
***********************************************************/
function author_info() {
if (is_author() || get_the_author_meta($type, $id)) {
$value = get_query_var('author_name');
$author = get_userdatabylogin($value);
$authorID = $author->ID;
$custom_avatar = get_the_author_meta('imageurl', $authorID);
if ($authorID=="1")
echo ' ';
elseif ($avatar)
$return = $avatar;
else
echo '<div class="author_profile author_'. $authorID .'">
<div class="author_avatar"><img alt="Author" src="'. $custom_avatar .'" width="140" height="140" /></div>
<div class="author_info">
<div class="author_description">
<p>'. get_the_author_meta('description', $authorID) .'</p>
<p><strong>Author\'s Website:</strong><a href="'. get_the_author_meta('user_url', $authorID) .'">'. get_the_author_meta('wesitename', $authorID) .'</a></p>
</div>
</div>
<div class="author_links">
<a href="https://plus.google.com/'. get_the_author_meta('google_plus', $authorID) .'" rel="me" target="_blank"><img alt="Google Plus Profile" src="'. get_the_author_meta('google_plus_icon', $authorID) .'" width="128" height="64" /></a>
<a href="http://www.facebook.com/'. get_the_author_meta('facebook', $authorID) .'" target="_blank"><img alt="Facebook Page" src="'. get_the_author_meta('facebook_icon', $authorID) .'" width="128" height="64" /></a>
<a href="http://twitter.com/'. get_the_author_meta('twitter', $authorID) .'" target="_blank"><img alt="Twitter Page" src="'. get_the_author_meta('twitter_icon', $authorID) .'" width="128" height="64" /></a>
<a href="http://www.linkedin.com/company/'. get_the_author_meta('linkedin', $authorID) .'" target="_blank"><img alt="LinkedIn Profile" src="'. get_the_author_meta('linkedin_icon', $authorID) .'" width="128" height="64" /></a>
</div>
</div>
';
?>
<?php }
}
add_action('thesis_hook_before_content', 'author_info');


I have been advised to use the following:

get_the_author_meta($type, $id) {
**Code to get value **
if(isset($value)) {
return $value;
} else {
return "#"; // Or some other string
}
}


However this solution will mean the links will still show up. If I do not want the links to show up at all the other option is to use:

if(isset(get_the_author_meta('google_plus', $authorID)) && isset(get_the_author_meta('google_plus_icon', $authorID))) :
<a href="https://plus.google.com/'. get_the_author_meta('google_plus', $authorID) .'" rel="me" target="_blank"><img alt="Google Plus Profile" src="'. get_the_author_meta('google_plus_icon', $authorID) .'" width="128" height="64" /></a>
endif;


Then only the links that have a href and a img will show up, but all empty div tags will still be shown.

So I am running out of ideas and in fact I cannot understand the logic in the last 2 pieces of script and clearly cannot understand where and how to use them. Other problem is the avatar, what I would like to achieve is be able to show the user image if link to the image is entered in user profile fields or show user avatar if field is empty.

Please talk to me in plain English since I am only learning php and not really pro to be able to understand the short-cuts.

Thanks

 

lorax




msg:4535980
 7:29 pm on Jan 14, 2013 (gmt 0)

Whoa. That looks like a lot of code. :) Are you following an example someplace or did you come up with this on your own?

AlexB77




msg:4535984
 7:36 pm on Jan 14, 2013 (gmt 0)

the very first part is all mine the rest is some suggestions I have had from here and there

AlexB77




msg:4536146
 11:00 am on Jan 15, 2013 (gmt 0)

Any chance of helping me here at all?

lorax




msg:4536174
 1:43 pm on Jan 15, 2013 (gmt 0)

I'm sorry but I won't be able to help at the level you're seeking. What I can say is that there are plenty of examples out there and even plugins (Search string: wordpress author bio page) that might do exactly what you're trying to do on your own. Since you're not an experienced PHP programmer perhaps you might want to utilize something that someone else has already built? Even if it doesn't do exactly what you want it will likely get you 90% of the way there AND one or more of these will likely have already built final piece you're searching for.

AlexB77




msg:4536205
 3:31 pm on Jan 15, 2013 (gmt 0)

Never mind, I have done it all

lorax




msg:4536286
 8:40 pm on Jan 15, 2013 (gmt 0)

Glad you got it sorted.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved