Page with random post

Yesterday we saw how to rescue old posts inside the loop ((Do not you know what the loop is ?, review this guide )) how about creating a personalized page that show a random post ?. Surely it is another interesting way for your readers to know all the material you have published.

Ya we saw how to add this type of trick in a place in your template specifically in the sidebar, but How about giving a place of merit as a page on your site. The process, although we have commented many times the initial part of creation of the "personalized page", is the following one:

Now, when your readers access to that new page they will see a post chosen at random by means of variable ' rand '.

Show a random post • WordPress Help

If you want, for example, to add a random post in your sidebar that changes on each page that is shown, you only have to edit your file ' sidebar.php ' (or whatever it's called in your theme ) and add in a new block the following:

This code will show you 1 post in the sidebar, with the title and extract of it. If you want to show more posts you just have to change '' showposts' => 1 'to another number you decide, and if you do not want to show the extract you just have to "comment" or delete the line' the_excerpt (); ', just like that.

Creating Rotating Banners • WordPress Help

Not so long ago we present you a super plugin to display rotating banners in your blog WordPress but as I know that since then you've learned a lot, it's time that learn to do it without plugin with pure and hard PHP code .

To generate the necessary code we will use the PHP function rand () , a wonder that not only allows to play with banners although with this example we will see its possibilities.

The idea of ​​this trick can show several ads when you have little space to put them. The code that I have prepared creates a random number between 0 and 10. And, since we want the ads to be shown with a probability of showing one or the other of 50%, I have set the condition " if" ' x> 5 '. As always, you can change these numbers to adapt the code to your needs.

You put the code in the place of the template where you want your ads to appear and you already have it.