Hi Peeps,
Am setting up a site and have managed to use some PHP to display a snippet of the blog posts on a static page within the site.
What I really need to do is to somehow specify it to only show posts from certain categories.
Could anyone help? The code I used is below..
<?php
/*Turn off error reporting.*/
error_reporting(0);
/*Configure database connection*/
$dbhost = 'internal-db.s12969.gridserver.com';
$dbuser = 'xxxxxxx';
$dbpass = '[stop looking!]';
/*Connect to the database.*/
$conn = mysql_connect ($dbhost, $dbuser, $dbpass)
or die
('There was an error connecting to the database.');
/*Select WordPress database.*/
$dbname = 'db12969_moments';
mysql_select_db ($dbname);
/*Get data from the database*/
//Use $howmany variable to define how many entries to display
$howmany = 2;
$result = mysql_query("SELECT * FROM wp_posts WHERE <code>post_type<code>=\"post\" and</code>post_status
= \"publish\" ORDER BY post_date desc LIMIT " . $howmany);
/*Display the data*/
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
//Date function
$datevalue = $row['post_date'];
$dateArray=explode('-',$datevalue);
// Example of results
// $dateArray[0]= 2007
// $dateArray[1] = 02
// $dateArray[2] = 05
?> <p class="small_grey_text"> <?php
echo date('F j, Y', mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0]));
echo "</p>";
// result: Feb 2, 2007
// Explode (Time) Code found on PHP.net at the following URL: http://www.php.net/manual/en/function..php#72953 ?>
<div class="hp_blog_title">
<a>" title="<?php echo "{$row['post_title']}";?>">
<?php echo "{$row['post_title']}";?></a>
</div>
<p><?php echo "{$row['post_excerpt']}";?></p>
<?php }
//Free the memory and then
mysql_free_result($result);
//Close the database connection.
mysql_close ($conn); ?>
</code>
Any help would be much appreciated.. many thanks in advance.