Displaying recent posts on external non-blog page…
-
I’m trying to display the 3 most recent posts from my blog on my main site’s home page. I’m using this test page as my home page and it’s working beautifully so far. My blog is located at https://www.mojolocoblog.com.
I’m using the following code on my external non-blog page….
<?php //db parameters $db_username = '###'; $db_password = '###'; $db_database = '###'; //connect to the database mysql_connect(localhost, $db_username, $db_password); @mysql_select_db($db_database) or die("Unable to select database"); //get data from database -- !IMPORTANT, the "LIMIT 5" means how many posts will appear. Change the 5 to any whole number. $query = "Select * FROM wp_posts WHERE post_type='post' AND post_status='publish' AND post_category='News Flash' ORDER BY id DESC LIMIT 3"; $query_result = mysql_query($query); $num_rows = mysql_numrows($query_result); //close database connection mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>test wordpress connect...</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <ul> <?php for($i=0; $i< $num_rows; $i++){ $blog_date = mysql_result($query_result, $i, "post_date"); $blog_title = mysql_result($query_result, $i, "post_title"); $blog_content = mysql_result($query_result, $i, "post_content"); $blog_permalink = mysql_result($query_result, $i, "guid"); $blog_date = strtotime($blog_date); $blog_date = strftime("%b %e", $blog_date); ?> <li class="home-list"><a href=”<?php echo $blog_permalink; ?>”><?php echo $blog_date; ?>: <?php echo $blog_title; ?></a></li> <?php } ?> </ul> </body> </html>
My question is this:
how can I call entries ONLY from one specific category? I don’t want to display random blog entries- only entries from the News Flash category. I’ve tried several things, but can’t seem to get it to work.
Any ideas?
Viewing 14 replies - 1 through 14 (of 14 total)
Viewing 14 replies - 1 through 14 (of 14 total)
- The topic ‘Displaying recent posts on external non-blog page…’ is closed to new replies.