PHP to show a random post from a specified category
-
I have a wordpress blog and a website on the same server. At the moment I have the below php code displaying the latest wordpress blog entry from a specified category. I want to be abl to display an entry from this category at random, not just the latest one
Can anyone ammend this code to help me to do this?
<?php
/**
*
* Change “path/to/” to the actual path of this file witch is in the root of your blog
*
*/
require(‘blog/wp-blog-header.php’);
query_posts(‘category_name=Mum and Baby&showposts=1’);
while (have_posts()) :
the_post();/**
*
* Change “was just posted in ” if you need. You can change the “,”
*as this is how the categories will be divided if the post is in
*more than one categorie
*
*/
echo ‘<h1 style=”color:#ff0066;font-family:Helvetica,Arial,sans-serif;font-weight:bold;font-size:1.0em;”>’;
the_title();
echo ‘</h1>’;echo ‘<h4 style=”font-size:0.8em;color:#666666;font-family:Georgia,”Times New Roman”,Times,serif;font-size:0.8em;font-style:italic;”>’;
the_date();
echo ‘</h4>’;echo ‘<h1 style=”color:#666666;font-family:Helvetica,Arial,sans-serif;;font-weight:normal;font-size:0.8em;”>’;
echo “posted in”;echo ‘<div style=”text-align:left;”>’;
the_category(‘, ‘);/**
*
* If you need the content of the post here it is… but I thought that you need only the title.
*
*/
echo ‘
‘;
echo ‘
‘;
echo ‘<div style=”text-align:left;”>’;
the_content();/**
*
* And delete or edit the style of the link to the blog’s post below.
*
*/echo ‘
<a href=”‘;
the_permalink();
echo ‘” rel=”bookmark”>Check out the blog’;
echo ‘</div>’;endwhile;
?>
The topic ‘PHP to show a random post from a specified category’ is closed to new replies.