Recent Post Problem
-
So I am trying to put recent posts on a non wordpres page and using the following code…
<?php //db parameters $db_username = 'XXX'; $db_password = 'XXX'; $db_database = 'XXX'; $blog_url = 'XXX'; //base folder for the blog. Make SURE there is a slash at the end //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' ORDER BY id DESC LIMIT 10"; $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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head></head> <body> <?php //start a loop that starts $i at 0, and make increase until it's at the number of rows for($i=0; $i< $num_rows; $i++){ //assign data to variables, $i is the row number, which increases with each run of the loop $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"); //use this line for p=11 format. $blog_permalink = $blog_url . mysql_result($query_result, $i, "post_name"); //combine blog url, with permalink title. Use this for title format //format date $blog_date = strtotime($blog_date); $blog_date = strftime("%b %e", $blog_date); //the following HTML content will be generated on the page as many times as the loop runs. In this case 5. ?> <div class="hp-latest-news"> <span style="font-weight: bold;"><?php echo $blog_date; ?>:</span> <a href="<?php echo $blog_permalink; ?>"><?php echo $blog_title; ?></a><br /> </div> <?php } //end the for loop ?> </body> </html>here is the sample page
http://www.empyrelounge.com/news.phpmy question is what should i change on the date to have them display in order since they are currently out of order
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Recent Post Problem’ is closed to new replies.