First, you need to create an author.php
file, or edit the one that your theme has, in my case, I did the test with the twentyseventeen and it doesn’t have an author.php
file, so I created it.
<?php
/**
* The template for displaying all single posts
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
* @version 1.0
*/
get_header(); ?>
<?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_id) : get_userdata(intval($author));
?>
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
global $query_string;
query_posts( $query_string . '&posts_per_page=1' );
while (have_posts()) : the_post(); ?>
<a href="https://wordpress.stackexchange.com/questions/312855/<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php the_content(); ?>
<?php endwhile;?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
</div><!-- .wrap -->
<?php
get_footer();
The key section is:
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_id) : get_userdata(intval($author));
In which we are getting the current user, and then we show the last post and since we only want the last one we say posts_per_page=1
.