wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Create most recent posts dashboard widget

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will create a new dashboard widget showing the five most recent posts.

snippet :  PHPcopy
function wps_recent_posts_dw() {
?>
   <ol>
     <?php
          global $post;
          $args = array( 'numberposts' => 5 );
          $myposts = get_posts( $args );
		foreach( $myposts as $post ) :  setup_postdata($post); ?>
		    <li> (<? the_date('Y / n / d'); ?>) <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
	  <?php endforeach; ?>
   </ol>
<?php
}
function add_wps_recent_posts_dw() {
       wp_add_dashboard_widget( 'wps_recent_posts_dw', __( 'Recent Posts' ), 'wps_recent_posts_dw' );
}
add_action('wp_dashboard_setup', 'add_wps_recent_posts_dw' );

Did you like this post? If so please share it with your friends. Thanks!

  • andriansah

    this is what i’m looking for,

    thank you

  • Manuel

    add to category: dashboard