How To Display Recent Articles On Homepage

0
1685
views


There is a different ways to display recent articles on wordpress homepage. On this tutorial, i will show you how to simply display recent articles on your wordpress homepage by using a functions, no need of plugins or widgets that use a lot of wordpress requests and can slow down your blog.

Display Recent Articles On Homepage

Display Recent Articles On Homepage

Displaying Recent Articles in a List Format

The list format is mostly used in sidebars of WordPress pages. You can display the recent posts by simply pasting the following code in a template file! for example sidebar.php:

<?php wp_get_archives( array( 'type' => 'postbypost', 'limit' => 20, 'format' => 'html' ) ); ?>

You can modify the number 20 with the number of posts you like to display.
Now You can simply Open the widgets page and add Recent Posts widget to your sidebar.

Displaying Recent Articles With Summary

You can use this Code And you make sure that the excerpt is a short description of the post.

<ul>
<?php $the_query = new WP_Query( 'showposts=5' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<li><?php the_excerpt(__('(moreā€¦)')); ?></li>
<?php endwhile;?>
</ul>

Another way to limit the number of characters displayed in the content is by manually stripping out post content during the query to display only a limited number of characters.

<ul>
  <?php $the_query = new WP_Query( 'showposts=5' ); ?>

  <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
  <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>

  <li><?php echo substr(strip_tags($post->post_content), 0, 150);?></li>
  <?php endwhile;?>
</ul>

You may change the 150 to set the character limit of your desire.

Goodluck

If you found this article useful for you please share it with your friends on social networks such google+ and facebook! You can always follow us on Facebook and add us to your Google+ circles.


LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.