Skip to content

Instantly share code, notes, and snippets.

@rosshanney
Created April 22, 2012 22:02
Show Gist options
  • Save rosshanney/2467193 to your computer and use it in GitHub Desktop.
Save rosshanney/2467193 to your computer and use it in GitHub Desktop.
Author bio template
<?php
/*
Template name: Author Bio
*/
?>
<?php get_header(); ?>
<?php //First output the page content (bio etc) ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content"><?php the_content(); ?></div>
</div>
<?php endwhile; endif; ?>
<?php //Retrieve the author name from the custom field ?>
<?php $author = get_post_meta( get_the_ID(), 'author_name', true ); ?>
<?php //Run a query for posts by the required author. Limit to 5 ?>
<?php $recent_posts = new WP_Query( array( 'author_name' => $author, 'posts_per_page' => 5 ) ); ?>
<?php //If some posts were found ?>
<?php if ( $recent_posts->have_posts() ) : ?>
<ul>
<?php //Loop through the found posts, outputting a link to each ?>
<?php while ( $recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment