How To Display Last Recent Updates List WordPress Beginners Tricks

To display wordpress recent upadates, in this article will help you to display your last posts in recent updates on your wordpress site. beginners needs to know about best wordpress practice to make their blog own stylish. some of new wordpress developer and designers don’t know how to start wordpress and how to make functions. if you are a new developer in wordpress, you need to know needed some wordpress tricks to increase you idea about wordpress development. below i was linked some useful wordpress tricks article, you can read more for getting ideas and code functions for wordpress development. So, guys, now we are going to make recent updates in our wordpress theme index.php file.

 

Recent Updates

In the wordpress code will help you to display wordpress recent post updates function, you can call last list of posts to your theme file where you want to show it up.  at first go to your wordpress theme folder and find where the functions.php file, or navigate from WP admin panel – Appearance>Editor>functions.php then copy past the below code after <?php tag.

function wpb_lastupdated_posts() { 

// Query Arguments
$lastupdated_args = array(
'orderby' => 'modified',
'ignore_sticky_posts' => '1'
);

//Loop to display 5 recently updated posts
$lastupdated_loop = new WP_Query( $lastupdated_args );
$counter = 1;
$string .= '<ul>';
while( $lastupdated_loop->have_posts() && $counter < 5 ) : $lastupdated_loop->the_post();
$string .= '<li><a href="' . get_permalink( $lastupdated_loop->post->ID ) . '"> ' .get_the_title( $lastupdated_loop->post->ID ) . '</a> ( '. get_the_modified_date() .') </li>';
$counter++;
endwhile; 
$string .= '</ul>';
return $string;
wp_reset_postdata(); 
} 

//add a shortcode
add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');

remember, the above function only output 5 updates, to change or increase limit of showing wordpress recent updates simply edit the function < 5 replace the number if you want 10.

now copy and past the below code to index.php file or anywhere to showing the recent updates from your wordpress last updates.

<?php 
if (function_exists(wpb_lastupdated_posts)) : 
wpb_lastupdated_posts();
endif;
?>

Now Refresh your website to see effects. Hope the wordpress tricks will help you a lot. if you face any kind of problems, just drop your comments.

 

We will be happy to hear your thoughts

Leave a reply

Register New Account
Reset Password