Skip to content

Instantly share code, notes, and snippets.

@IngmarBoddington
Created August 2, 2012 14:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save IngmarBoddington/3237598 to your computer and use it in GitHub Desktop.
Save IngmarBoddington/3237598 to your computer and use it in GitHub Desktop.
Example authors page template for multi-author WordPress blogs
<?php
/*
Template Name: Authors
*/
?>
<?php get_header(); ?>
<!-- BEGIN #content-wrap -->
<div id="content-wrap" class="clearfix">
<div id="content-top">&nbsp;</div>
<!--BEGIN #primary .hfeed-->
<div id="primary" class="hfeed">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!--BEGIN .hentry -->
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1 class="entry-title"><?php the_title(); ?></h1>
<!--BEGIN .entry-content -->
<div class="entry-content">
<?php the_content(); ?>
<!--BEGIN .archive-lists -->
<div class="archive-lists">
<?php
//Ing - Code for displaying all authors info
global $wpdb;
$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY user_nicename");
$blog_name = 'The Online Retailing Blog';
foreach ($user_ids as $user_id) {
//Get all the info
$user = get_userdata($user_id);
list($user_description) = $wpdb->get_col("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'description' AND user_id = $user_id");
list($user_first_name) = $wpdb->get_col("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'first_name' AND user_id = $user_id");
$user_link = get_author_posts_url($user_id);
$user_name = $user->data->display_name;
$user_avatar = get_avatar($user->data->user_email, 70);
$user_url = $user->data->user_url;
$user_url_link = ($user_url != '' ? '<a href="' . $user_url . '">' . $user_name . '</a>' : $user_name);
$user_post_count = count_user_posts($user_id);
$user_post_cost_suffix = ($user_post_count == 1 ? 'post' : 'posts');
//Ensure only Authors (with more than one post) get outputted
if (($user->caps['author'] == 1) && ($user_post_count > 0)) {
//Output author block
echo '
<!--BEGIN .author-bio-->
<div class="author-bio">
<!-- BEGIN .author-inner -->
<div class="author-inner clearfix">
<!-- BEGIN .author-wrap -->
<div class="author-wrap clearfix">
' . $user_avatar . '
<div class="author-info">
<div class="author-title">' . $user_url_link . '</div>
<div class="author-description">' . $user_description . '<br />' . $user_first_name . ' has made <a href="' . $user_link . '">' . $user_post_count . ' ' . $user_post_cost_suffix . '</a> on ' . $blog_name . '</div>
</div>
<!-- END .author-wrap -->
</div>
<!-- END .author-inner -->
</div>
<!--END .author-bio-->
</div>';
}
}
?>
<!--END .archive-lists -->
</div>
<!--END .entry-content -->
</div>
<!--END .hentry-->
</div>
<?php endwhile; else: ?>
<!--BEGIN #post-0-->
<div id="post-0" <?php post_class() ?>>
<h1 class="entry-title"><?php _e('Error 404 - Not Found', 'framework') ?></h1>
<!--BEGIN .entry-content-->
<div class="entry-content">
<p><?php _e("Sorry, but you are looking for something that isn't here.", "framework") ?></p>
<?php get_search_form(); ?>
<!--END .entry-content-->
</div>
<!--END #post-0-->
</div>
<?php endif; ?>
<!--END #primary .hfeed-->
</div>
<div id="content-btm">&nbsp;</div>
<!-- END #content-wrap -->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
@chinmayrajyaguru
Copy link

That's working perfectly. But I have created new role for contributors through function.php.
add_action( 'wp_loaded', 'add_new_contributor_plus_role'); function add_new_contributor_plus_role() { add_role( 'contributor_plus', __( 'Contributor Plus' ), array( 'edit_posts' => true, 'delete_posts' => false, 'read' => true, 'upload_files' => true, 'publish_posts' => false, 'delete_published_posts' => false, 'edit_published_posts' => false ) ); }

How can I put this new contributor in above code?

@chinmayrajyaguru
Copy link

I have added new contributor and also it can help to add any role you want by this way...

if (($user->caps['author'] == 1) && ($user_post_count > 0)) {
...
}

From

if (($user->caps['contributor_plus'] == 1) || ($user->caps['author'] == 1) && ($user_post_count > 0)) {
...
}

Thank you for share this wonderful #gist man!

@wushu24
Copy link

wushu24 commented May 29, 2018

this code is just perfect!
it works like charm, but what if i want to add social media links in (author-bio) box... how should it be done?
i tried some codes but useless !
Appreciate your help!

@techlanka
Copy link

Is it possible to add this my github pages site????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment