Created
March 26, 2012 20:12
-
-
Save fritids/2209326 to your computer and use it in GitHub Desktop.
wordpress-archive-page-with-all-authors-and-all-posts/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//http://www.scottbressler.com/blog/2011/03/wordpress-archive-page-with-all-authors-and-all-posts/ | |
/** | |
* Template Name: All Author Archives | |
* Code: Scott Bressler (http://www.scottbressler.com/blog) | |
* Explanation: http://www.scottbressler.com/blog/2011/03/wordpress-archive-page-with-all-authors-and-all-posts | |
*/ | |
get_header(); ?> | |
<div id="container"> | |
<div id="content"> | |
<div id="all-authors-archive"> | |
<h1><?php the_title(); ?></h1> | |
<?php | |
// Arguments to pass to get_users | |
$args = array( 'orderby' => 'display_name', 'order' => 'ASC', 'who' => 'authors' ); | |
// Query for the users | |
$authors = get_users( $args ); ?> | |
<div id="authors-listing"><p><strong>Authors: </strong> | |
<?php | |
// Loop through all the users, printing their names, with links to their section of the archives | |
for ( $i = 0; $i < count( $authors ); ++$i ) { | |
$author = $authors[$i]; | |
echo "<a href='#{$author->user_nicename}'>$author->display_name</a>"; | |
if ( $i < count( $authors ) - 1 ) { | |
echo ' | '; | |
} | |
} ?> | |
</p></div> | |
<?php | |
// Loop through all the users, printing all of their posts as we go | |
foreach ( $authors as $author ) { ?> | |
<a name="<?php echo $author->user_nicename; ?>"></a> | |
<div class="author-posts-wrapper" id="author-<?php echo $author->ID; ?>-posts-wrapper"> | |
<div class="author-avatar" id="author-<?php echo $author->ID; ?>-avatar"> | |
<?php echo get_avatar( $author->ID, 96 ); ?> | |
</div> | |
<div class="author-posts" id="author-<?php echo $author->ID; ?>-posts"> | |
<h2><a href="<?php echo get_author_posts_url( $author->ID ); ?>"><?php echo $author->display_name; ?></a></h2> | |
<?php | |
// Set up a Loop, querying for all of the current user's posts | |
$args = array( 'author' => $author->ID, 'posts_per_page' => -1 ); | |
$posts = query_posts($args); | |
// Now that we have the posts, simulate a Loop here or use get_template_part | |
// if we already have the output in another template, like: | |
// get_template_part( 'loop', 'all-authors' ); // Pulls in loop-all-authors.php from theme | |
if ( have_posts() ) : ?> | |
<ul class="author-post-list" id="author-<?php echo $author->ID; ?>-post-list"> | |
<?php while ( have_posts() ) : the_post(); // Print whatever we want for each post - for now the title and date ?> | |
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> — <?php echo get_the_date(); ?></li> | |
<?php endwhile; ?> | |
</ul><!-- #author-post-list --> | |
<?php else: ?> | |
<p>This author has not yet published any posts</p> | |
<?php endif; ?> | |
</div><!-- #author-posts --> | |
</div><!-- #author-posts-wrapper --> | |
<?php } // End looping over all users ?> | |
<p>See <a href="http://www.scottbressler.com/blog/2011/03/wordpress-archive-page-with-all-authors-and-all-posts">this post</a> for an explanation of the motivation behind this page</p> | |
</div><!-- #all-authors-archive --> | |
</div><!-- #content --> | |
</div><!-- #container --> | |
<style type="text/css"> | |
/* We would certainly put this in a separate file for production use */ | |
#all-authors-archive h1 { | |
margin-bottom: 15px; | |
} | |
#all-authors-archive h2, | |
#all-authors-archive .author-posts-wrapper { | |
margin-bottom: 10px; | |
} | |
#all-authors-archive .author-posts-wrapper { | |
position: relative; | |
padding-left: 111px; | |
min-height: 106px; | |
} | |
#all-authors-archive .author-avatar { | |
position: absolute; | |
left: 0; | |
} | |
#all-authors-archive .author-post-list li { | |
word-wrap: break-word; | |
font-size: 14px; | |
} | |
</style> | |
<?php | |
get_sidebar(); | |
get_footer(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment