How to get page id by slug wordpress theme

Show Random Posts on page with WordPress

If you want to show random posts each time a client visits. There are many wordpress plugins which will give similar functionality. We have simple code for showing random posts which you need add in your wordpress theme.

Show Random Posts on page with WordPress

You need to create random.php page in your template.  In that page just copy paste the following code:


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
query_posts(array('orderby' => 'rand', 'showposts' => 1));
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1>php the_permalink() ?>"><!--?php the_title(); ?--></h1>
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php the_content(); ?>

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php endwhile;
endif; ?>

Than create page through wordpress admin panel and select the random page template.

random-wordpress-posts
Show Random Posts on page with WordPress

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.