PHP author list with conditional social icons
-
Here’s the code:
<?php $display_admins = false; // not displaying GUESTS see below $order_by = 'display_name'; // 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count' $role = ''; // 'subscriber', 'contributor', 'editor', 'author' - leave blank for 'all' $avatar_size = 128; $hide_empty = true; // hides authors with zero posts if(!empty($display_admins)) { $blogusers = get_users('orderby='.$order_by.'&role='.$role); } else { $admins = get_users('role=guest'); $exclude = array(); foreach($admins as $ad) { $exclude[] = $ad->ID; } $exclude = implode(',', $exclude); $blogusers = get_users('exclude='.$exclude.'&orderby='.$order_by.'&role='.$role); } $authors = array(); foreach ($blogusers as $bloguser) { $user = get_userdata($bloguser->ID); if(!empty($hide_empty)) { $numposts = count_user_posts($user->ID); if($numposts < 1) continue; } $authors[] = (array) $user; } echo '<ul>'; foreach($authors as $author) { $display_name = $author['data']->display_name; $avatar = get_avatar($author['ID'], $avatar_size); $description = get_userdata($author['ID'])->user_description; $author_profile_url = get_author_posts_url($author['ID']); $LinkedIn = get_userdata($author['ID'])->LinkedIn; $googleplus = get_userdata($author['ID'])->googleplus; $twitter = get_userdata($author['ID'])->twitter; $position = get_userdata($author['ID'])->Position; echo '<div class="contributor"> <div class="contributor-avatar"> <a href="', $author_profile_url, '">', $avatar , '</a> </div> <div class="contributor-info"> <a href="', $author_profile_url, '"><h1>' , $display_name , '</h1> </a> <h3>' ,$position , '</h3>' , $description , '</br> <a href="' .$author_profile_url. '">Posts by ' , $display_name , ' </a> </p> </div> <div class="contributor-social"> //IF $LinkedIn !=""// { <a href="https://' , $LinkedIn , '"target="blank"> LinkedIn Image </a> } </div> </div> '; } ?>
I’ve pieced this together from a few sources and played with it a bit, since I’m not quite able to generate stuff like this on my own yet.
The question: under my “contributor-social” div, is it even possible to get the LinkedIn link to show only if the $LinkedIn custom field has been filled in? Thanks for any help!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘PHP author list with conditional social icons’ is closed to new replies.