Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save robneu/fbc37e33f02a9a37bf4d to your computer and use it in GitHub Desktop.

Select an option

Save robneu/fbc37e33f02a9a37bf4d to your computer and use it in GitHub Desktop.
A Genesis author box that uses template parts
<?php
/**
* The template part for displaying an author box on single entries.
*
* @see prefix_author_box()
* @see /includes/theme-functions.php
*
*/
?>
<div class="author-box">
<div class="one-third first">
<?php echo get_avatar( get_the_author_meta( 'email' ), 200 ); ?>
</div><!-- .one-third -->
<div class="two-thirds">
<h4 class="author-box-title"><a href="<?php echo esc_url( $archive ); ?>"><?php echo $name; ?></a></h4>
<p class="desc"><?php echo get_the_author_meta( 'description' ); ?></p>
</div><!-- .two-thirds -->
<div class="clear"></div>
<div class="simple-social-icons">
<ul class="alignleft">
<?php if ( $twitter ) { ?>
<li class="social-twitter">
<a href="<?php echo esc_url( $twitter ); ?>">&#xe80d; <span class="text">Follow Me</span></a>
</li>
<?php } ?>
<?php if ( $gplus ) { ?>
<li class="social-gplus">
<a href="<?php echo esc_url( $gplus ); ?>">&#xe801; <span class="text">Circle Me</span></a>
</li>
<?php } ?>
<?php if ( $facebook ) { ?>
<li class="social-facebook">
<a href="<?php echo esc_url( $facebook ); ?>">&#xe802; <span class="text">Friend Me</span></a>
</li>
<?php } ?>
<li class="social-rss">
<a href="<?php echo $rss_feed; ?>">&#xe805; <span class="text">Subscribe</span></a>
</li>
</ul>
</div><!-- .simple-social-icons -->
</div><!-- .author-box -->
<?php
/**
* The template part for displaying an author box.
*
* @see prefix_author_box()
* @see /includes/theme-functions.php
*
*/
?>
<div class="author-box">
<div class="one-third first">
<?php echo get_avatar( get_the_author_meta( 'email' ), 200 ); ?>
</div><!-- .one-third -->
<div class="two-thirds">
<h4 class="author-box-title"><a href="<?php echo esc_url( $archive ); ?>"><?php echo $name; ?></a></h4>
<p class="desc"><?php echo get_the_author_meta( 'description' ); ?></p>
</div><!-- .two-thirds -->
<div class="clear"></div>
</div><!-- .author-box -->
<?php
add_filter( 'genesis_author_box', 'prefix_author_box', 10, 6 );
/**
* Display Custom Author Boxes using template parts.
*
* @author Robert Neu
* @link http://wpbacon.com/tutorials/better-genesis-author-box/
*
* @param string $output
* @param string $context
* @param string $pattern
* @param string $gravatar
* @param string $title
* @param string $description
* @return string $output
*/
function prefix_author_box( $output, $context, $pattern, $gravatar, $title, $description ) {
$twitter = 'https://twitter.com/' . get_the_author_meta( 'twitter' );
$facebook = get_the_author_meta( 'facebook' );
$gplus = get_the_author_meta( 'googleplus' );
$rss_feed = trailingslashit( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . 'feed';
$archive = trailingslashit( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
$name = get_the_author();
// Author box on single posts.
if ( 'single' !== $context ) {
ob_start();
include_once( locate_template( 'templates/partial/author-box.php' ) );
$output = ob_get_clean();
}
else {
ob_start();
include_once( locate_template( 'templates/partial/author-box-single.php' ) );
$output = ob_get_clean();
}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment