Because of the natural structure regarding blogs, articles turn out to be buried down if they get old. Most new users join and pick up as soon as they join, and they also never bother returning to college to one of your respective good posts. One of many easiest way to provide a new life to your older posts can be by displaying them inside sidebar. In this kind of tutorial, we will share ways to display random posts with your WordPress.
It is also a powerful snippet to get more page views on your blog like you can add a heading of trending to it so on every reload this list of posts will be changed and the visitor click every time a new post and will think that its really now tending. You can also add the heading that last visit saw this so you current visitor will also see that what was other last visiting as its human natures so its upto you to garb your visitor attentions.
Now without any more preface garb the code from below and add it to the perfect place where you think it should be.
1.) It simply displays a list of random posts along with post-excerpts.
2.) Code used here displays 5 random posts and that value can be changed.
3.) You can use it in your WordPress theme anywhere.
<div> <h2>Random Posts</h2> <ul> <?php $args = array( 'numberposts' => 5, 'orderby' => 'rand', 'post_status' => 'publish', 'offset' => 1 ); $rand_posts = get_posts( $args ); foreach( $rand_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><p><?php the_excerpt(); ?></p></li> <?php endforeach; ?> </ul> </div>
You can edit it with with your requirement also. You can also add date, time, thumbs, comments, authors and anyhting that a post have. Rest all is done.
Theme Files Editing Warning:
Keep in mind that every code that you will add in your themes files will be removed when you will change the theme. So after changing your theme, you have to follow this article again and you will get everything back same as it is now.
This is what we have and shared in easy steps for newbies so that they can easily know how it works. Stay with us because we are going to share a whole guide step by step about WordPress and make it easy for you. If you liked it then share it and be with us to get next tutorial. If you have any problem then feel free to ask us. We will help you with what we can or have.