<?php if ( have_posts() ) : ?> | |
<?php | |
/**Get all of the data about the author from the WordPress and Pods generated user profile fields.**/ | |
//First get the_post so WordPress knows who's author page this is | |
the_post(); | |
//get the author's meta data and store in array $user | |
$user = get_userdata( get_the_author_meta('ID') ); | |
//Escape all of the meta data we need into variables | |
$name = esc_attr($user->user_firstname) . ' ' . esc_attr($user->user_lastname); | |
$title = esc_attr($user->title); | |
$email = esc_attr($user->user_email); | |
$phone = esc_attr($user->phone_number); | |
$street_1 = esc_attr($user->street_address_line_1); | |
$street_2 = esc_attr($user->street_address_line_2); | |
$city = esc_attr($user->city); | |
$state = esc_attr($user->state); | |
$zip = esc_attr($user->zip_code); | |
$website = esc_url($user->user_url); | |
$twitter = esc_url($user->twitter); | |
$linkedin = esc_url($user->linkedin); | |
?> |
<article> | |
<header class="entry-header"> | |
<h1 class="entry-title"><?php _e( 'User Profile', 'twentytwelve' ); ?></h1> | |
</header> | |
<div class="author-info"> | |
<h2><?php echo $name; ?></h1> | |
<div class="author-avatar"> | |
<?php echo '<a href="' . pods_image_url( $user->picture, 'large') . '">' . pods_image ( $user->picture, 'thumbnail') . '</a>'; | |
?> | |
</div><!-- .author-avatar --> | |
<div class="author-description"> | |
<p><strong><?php _e('Email:', 'twentytwelve'); ?></strong> <?php echo '<a href="mailto:' . $email . '">' . $email . '</a>'; ?></p> | |
<p><strong><?php _e('Phone:', 'twentytwelve'); ?></strong> <?php echo $phone; ?></p> | |
<div><p><strong><?php _e('Address:', 'twentytwelve'); ?> </strong></p> | |
<?php echo | |
'<p>' . $street_1 . '</p>' . | |
'<p>' . $street_2 . '</p>' . | |
'<p>' . $city . ', ' . $state . ' ' . $zip . '</p>'; | |
?></div> | |
<p><strong><?php _e('Website:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $website . '">' . $website . '</a>'; ?></p> | |
<p><strong><?php _e('Twitter:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $twitter . '">' . $twitter . '</a>'; ?></p> | |
<p><strong><?php _e('LinkedIn:', 'twentytwelve'); ?> </strong> <?php echo '<a href="' . $linkedin . '">' . $linkedin . '</a>'; ?></p> | |
</div><!-- .author-description --> | |
</div><!-- .author-info --> | |
</article> |
<ul> | |
<?php | |
$users = new WP_User_Query(array( | |
'meta_key'=>'last_name', | |
'orderby'=>'meta_value', | |
'fields'=>'all_with_meta' | |
)); | |
if ( ! empty( $users->results ) ) { | |
foreach ( $users->results as $user ) { | |
echo '<li><a href="' . esc_url( get_author_posts_url($user->ID) ) . '">' . esc_attr( $user->last_name ) . ', ' . esc_attr( $user->first_name ) . '</a></li>'; | |
} | |
} | |
else { | |
echo 'No users found.'; | |
} | |
?> | |
</ul> |
<?php | |
/* | |
Template Name: Users List | |
*/ | |
get_header(); ?> | |
<div id="primary" class="site-content"> | |
<div id="content" role="main"> | |
<article> | |
<header class="entry-header"> | |
<h1 class="entry-title"><?php _e( 'User Directory', 'twentytwelve' ); ?></h1> | |
</header> | |
<div class="entry-content"> | |
<ul> | |
<?php | |
$users = new WP_User_Query(array( | |
'meta_key'=>'last_name', | |
'orderby'=>'meta_value', | |
'fields'=>'all_with_meta' | |
)); | |
if ( ! empty( $users->results ) ) { | |
foreach ( $users->results as $user ) { | |
echo '<li><a href="' . esc_url( get_author_posts_url($user->ID) ) . '">' . esc_attr( $user->last_name ) . ', ' . esc_attr( $user->first_name ) . '</a></li>'; | |
} | |
} | |
else { | |
echo 'No users found.'; | |
} | |
?> | |
</ul> | |
</div> | |
</article> | |
</div><!-- #content --> | |
</div><!-- #primary --> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
<?php | |
function pods_user_profile_display($user) { | |
//Escape all of the meta data we need into variables | |
$name = esc_attr($user->user_firstname) . ' ' . esc_attr($user->user_lastname); | |
$title = esc_attr($user->title); | |
$email = esc_attr($user->user_email); | |
$phone = esc_attr($user->phone_number); | |
$street_1 = esc_attr($user->street_address_line_1); | |
$street_2 = esc_attr($user->street_address_line_2); | |
$city = esc_attr($user->city); | |
$state = esc_attr($user->state); | |
$zip = esc_attr($user->zip_code); | |
$website = esc_url($user->user_url); | |
$twitter = esc_url($user->twitter); | |
$linkedin = esc_url($user->linkedin); | |
?> | |
<div class="author-info"> | |
<h2><?php echo $name; ?></h1> | |
<div class="author-avatar"> | |
<?php echo '<a href="' . pods_image_url( $user->picture, 'large') . '">' . pods_image ( $user->picture, 'thumbnail') . '</a>'; | |
?> | |
</div><!-- .author-avatar --> | |
<div class="author-description"> | |
<p><strong><?php _e('Email:', 'twentytwelve'); ?></strong> <?php echo '<a href="mailto:' . $email . '">' . $email . '</a>'; ?></p> | |
<p><strong><?php _e('Phone:', 'twentytwelve'); ?></strong> <?php echo $phone; ?></p> | |
<div><p><strong><?php _e('Address:', 'twentytwelve'); ?> </strong></p> | |
<?php echo | |
'<p>' . $street_1 . '</p>' . | |
'<p>' . $street_2 . '</p>' . | |
'<p>' . $city . ', ' . $state . ' ' . $zip . '</p>'; | |
?></div> | |
<p><strong><?php _e('Website:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $website . '">' . $website . '</a>'; ?></p> | |
<p><strong><?php _e('Twitter:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $twitter . '">' . $twitter . '</a>'; ?></p> | |
<p><strong><?php _e('LinkedIn:', 'twentytwelve'); ?> </strong> <?php echo '<a href="' . $linkedin . '">' . $linkedin . '</a>'; ?></p> | |
</div><!-- .author-description --> | |
</div><!-- .author-info --> | |
<?php | |
} | |
?> |
<ul> | |
<?php | |
$users = new WP_User_Query(array( | |
'meta_key'=>'last_name', | |
'orderby'=>'meta_value', | |
'fields'=>'all_with_meta' | |
)); | |
foreach ($users as $user) { | |
pods_user_profile_display($user); | |
} | |
?> | |
</ul> |
<?php | |
/* | |
Template Name: Users List | |
*/ | |
get_header(); ?> | |
<div id="primary" class="site-content"> | |
<div id="content" role="main"> | |
<article> | |
<header class="entry-header"> | |
<h1 class="entry-title"><?php _e( 'User Directory', 'twentytwelve' ); ?></h1> | |
</header> | |
<div class="entry-content"> | |
<ul> | |
<?php | |
$users = get_users('orderby=user_lastname'); | |
foreach ($users as $user) { | |
pods_user_profile_display($user); | |
} | |
?> | |
</ul> | |
</div> | |
</article> | |
</div><!-- #content --> | |
</div><!-- #primary --> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
<ul> | |
<?php | |
$args = array( | |
'orderby' => 'user_lastname', | |
'role' => 'contributor' | |
'meta_key' => 'hide_from_directory', | |
'meta_value' => '', | |
); | |
$users = get_users($args); | |
foreach ($users as $user) { | |
echo '<li><a href="' . esc_url( get_author_posts_url($user->ID) ) . '">' . esc_attr($user->user_lastname) . ', ' . esc_attr($user->user_firstname) . '</a></li>'; | |
} | |
?> | |
</ul> |
<?php | |
$current_user_id = get_current_user_id(); | |
$current_user = new WP_User ( $current_user_id ); | |
if ($current_user->roles[0] == 'contributor' || 'administrator') { | |
//show profile | |
} | |
elseif ( ! is_user_logged_in() ) { | |
echo '<p><strong>You must be logged in to view the user directory.</strong></p>' | |
else { | |
echo '<p><strong>Sorry, but you do not have sufficient privileges to view the user directory.</p></strong>' | |
} | |
?> |
<?php | |
//Output a twitter follow button for post author. Must be used in loop | |
//See https://twitter.com/about/resources/buttons#follow for more info | |
function pods_twitter_follow() { | |
$twitter = get_the_author_meta('twitter'); | |
$name = get_author_meta('user_firstname'); | |
?> | |
<a class="twitter-follow-button" data-show-count="false" href="<?php echo $twitter; ?>">Follow <?php echo $name; ?></a> | |
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> | |
<?php | |
} | |
//Output a link to a user's twitter page | |
function pods_show_twitter_link($id) { | |
$twitter = get_user_meta($id, 'twitter', true); | |
echo esc_html($twitter); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment