I need to add the date and author to blog posts. The line needs to read like this example:
Posted on January 20, 2018 by Name
Clicking on the date will take you to a page with all posts published on that date. Clicking on the Name/author will take you to a page with all posts by that author.
I did some research and was able to find code to add to the single.php template.
<div class="sample">Posted on <?php the_date(); ?> by <?php
the_author(); ?></div>
I will need to create a class for "sample". How do I get the date and author to link where they need to go?
Here is the code for my single.php file:
<?php
/**
* The Template for displaying all single posts.
*
* @package WordPress
* @subpackage Cornerstone
* @since Cornerstone 1.0
*/
get_header(); ?>
<div class="row">
<div class="small-12 medium-12 columns">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="date">Posted on <?php the_date(); ?> by <?php
the_author(); ?></div>
<div class="breadcrumbs" xmlns:v="
vocabulary/#">
<?php if(function_exists('bcn_display')){bcn_display();}?>
</div>
</div>
</div>
<div class="row">
<div id="primary" class="site-content small-12 medium-8 columns">
<div id="content" role="main">
<?php do_action( 'cornerstone_before_content' ); ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php do_action( 'cornerstone_after_content' ); ?>
</div>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
I need to add the date and author to blog posts. The line needs to read like this example:
Posted on January 20, 2018 by Name
Clicking on the date will take you to a page with all posts published on that date. Clicking on the Name/author will take you to a page with all posts by that author.
I did some research and was able to find code to add to the single.php template.
<div class="sample">Posted on <?php the_date(); ?> by <?php
the_author(); ?></div>
I will need to create a class for "sample". How do I get the date and author to link where they need to go?
Here is the code for my single.php file:
<?php
/**
* The Template for displaying all single posts.
*
* @package WordPress
* @subpackage Cornerstone
* @since Cornerstone 1.0
*/
get_header(); ?>
<div class="row">
<div class="small-12 medium-12 columns">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="date">Posted on <?php the_date(); ?> by <?php
the_author(); ?></div>
<div class="breadcrumbs" xmlns:v="http://rdf.data-
vocabulary/#">
<?php if(function_exists('bcn_display')){bcn_display();}?>
</div>
</div>
</div>
<div class="row">
<div id="primary" class="site-content small-12 medium-8 columns">
<div id="content" role="main">
<?php do_action( 'cornerstone_before_content' ); ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php do_action( 'cornerstone_after_content' ); ?>
</div>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Share
Improve this question
edited Aug 8, 2018 at 13:53
Webman
asked Aug 7, 2018 at 21:39
WebmanWebman
631 silver badge11 bronze badges
2
- Page template code added to question. – Webman Commented Aug 8, 2018 at 13:54
- I’m also looking for the same solution to add the post date at the bottom of the article. My website is hosted on WordPress. – Helmet Savvy Commented Feb 1, 2021 at 6:43
1 Answer
Reset to default 2Use the following code in file template single.php
(https://developer.wordpress/reference/functions/get_day_link/#user-contributed-notes ) :
<?php
$archive_year = get_the_time( 'Y' );
$archive_month = get_the_time( 'm' );
$archive_day = get_the_time( 'd' );
$month= get_the_date('M');
?>
<div class="custom_archives">
<p>
Posted on: <a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>"><?php echo $month. " ".$archive_day.", " .$archive_year; ?>
</a>
</p>
<p>
<a class="author-link" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author"><?php printf( __( 'View all posts by %s', 'twentysixteen' ), get_the_author() ); ?>
</a>
</p>
</div>
The first link is the daily archive, the second the author archive