Saturday, May 21, 2016

WordPress get recent posts

In WordPress we can get recently added posts.

To get recently added posts in WordPress user the following function.

<?php
$args = array( 'numberposts' => 6, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$posts_list = get_posts( $args );
echo '<ul>';
foreach ($posts_list as $post) :  setup_postdata($post); ?>
<li><strong><?php the_date(); ?></strong><br />
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>"> <?php the_title(); ?></a>
</li>
        <?php endforeach; ?>
       </ul>

 The above code can be used anywhere in the website and in any template.

No comments:

Post a Comment

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...