Skip to content

Instantly share code, notes, and snippets.

@landbryo
Created April 17, 2023 17:08
Show Gist options
  • Save landbryo/615e2c0807bc462d9144f42205138a6b to your computer and use it in GitHub Desktop.
Save landbryo/615e2c0807bc462d9144f42205138a6b to your computer and use it in GitHub Desktop.
Alternative author archive template.
<?php
/**
* The template for displaying author archive pages.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package Plugin_Core
*/
use PluginCore\Authors;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
global $authordata;
$author_id = $authordata->ID;
$author_name = get_the_author() ? get_the_author() : '';
$author_title = get_user_meta( $author_id, 'display_title', true );
$career_advice = get_user_meta( $author_id, 'career_advice', true );
$education = get_user_meta( $author_id, 'education', true );
$socials = Authors::plugin_get_author_socials( $author_id );
$img_path = plugin()->get_plugin_path() . 'src/img/';
$education_icon = file_get_contents( $img_path . 'trophy.svg' );
$advice_icon = file_get_contents( $img_path . 'chat.svg' );
get_header(); ?>
<?php do_action( 'plugin_before_primary' ); ?>
<div id="primary">
<?php
if ( function_exists( 'yoast_breadcrumb' ) ) {
yoast_breadcrumb( '<div class="plugin-breadcrumbs">', '</div>' );
}
?>
<section class="plugin-author__grid">
<div class="plugin-author__head">
<div class="plugin-author__avatar-wrapper">
<?php echo get_avatar( $author_id, 100, '', '', [ 'class' => 'plugin-author__avatar' ] ); ?>
</div>
<div class="plugin-author__meta">
<h1 class='plugin-author__name'><?php echo esc_html( $author_name ); ?></h1>
<div class='plugin-author__title'><?php echo esc_html( $author_title ); ?></div>
<?php if ( ! empty( $socials ) ) { ?>
<ul class="plugin-author__socials">
<?php foreach ( $socials as $social_key => $social ) { ?>
<li class="plugin-author__socials--<?php echo esc_attr( $social_key ); ?>">
<a target="_blank" href="<?php echo esc_url_raw( $social['link'] ); ?>">
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $social['icon'];
?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
</div>
</div>
<div class="plugin-author__description">
<?php echo wp_kses_post( get_the_author_meta( 'description', $author_id ) ); ?>
</div>
</div>
<div class="plugin-author__col plugin-author__col--side">
<?php if ( ! empty( $career_advice ) ) { ?>
<div class="plugin-author__details plugin-author__details--advice">
<div class="plugin-author__details-icon">
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $advice_icon;
?>
</div>
<div class="plugin-author__details-inner">
<h2><?php _e( 'Favorite Career Advice', 'plugin-core' ); ?></h2>
<p><?php echo wp_kses_post( $career_advice ); ?></p>
</div>
</div>
<?php } ?>
<?php if ( ! empty( $education ) ) { ?>
<div class="plugin-author__details plugin-author__details--education">
<div class="plugin-author__details-icon">
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $education_icon;
?>
</div>
<div class="plugin-author__details-inner">
<h2><?php _e( 'Experience Highlights', 'plugin-core' ); ?></h2>
<?php echo wp_kses_post( $education ); ?>
</div>
</div>
<?php } ?>
</div>
<?php if ( have_posts() ) { ?>
<div class="plugin-archive__posts">
<h2><?php _e( 'Latest Articles', 'plugin-core' ); ?></h2>
<div class="plugin-archive__posts-inner">
<?php
while ( have_posts() ) {
the_post();
?>
<article class="plugin-archive__post">
<div class="plugin-archive__post-inner">
<div class="plugin-archive__post-categories">
<?php the_category(); ?>
</div>
<div class="plugin-archive__post-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</div>
<div class="plugin-archive__post-excerpt">
<?php the_excerpt(); ?>
</div>
</div>
<div class="plugin-archive__post-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'medium' ); ?>
</a>
</div>
</article>
<?php } ?>
</div>
</div>
<?php } ?>
<?php
the_posts_pagination(
[
'class' => 'plugin-pagination',
'prev_text' => _x( 'Prev', 'previous set of posts', 'plugin-core' ),
'next_text' => _x( 'Next', 'next set of posts', 'plugin-core' ),
]
);
?>
</div><!-- #primary -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment