Which wp_get_recent_posts()
do you retrieve the most recent posts. For meta data, like published date and modified date use additional functions.
For the published date is the_date()
helpful.
For the modified date use the_modified_date()
.
The functions are a part of the Template Tags, useful for Theme and direct output. But she have also parameters to get the values for custom echo.
A small example:
<h2>Recent Posts</h2>
<ul>
<?php
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"])
. '">' . $recent["post_title"]
. '</a> Published on '
. the_date( $echo = FALSE )
. ', Modified on '
. the_modified_date( $echo = FALSE )
. '</li> ';
}
?>
</ul>
The example is not ready to use, especially translation ready. Enhance with the i18n functions from WordPress to create a solid, translatable and sanitized result with the helper functions for this topic, like esc_attr_e()
, esc_attr__()
and printf()
.
If you don’t like to use the parameters on the functions, more short. Then use the functions, there was used inside the Template Tags – get_the_modified_date()
and get_the_date()
.