Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //db parameters
- $db_username = 'XXXX';
- $db_password = 'XXXX';
- $db_database = 'XXXX';
- $db_host = 'XXXX';
- $blog_url = 'http://mywebsite.com/blog/'; //base folder for the blog. Make SURE there is a slash at the end
- //connect to the database
- mysql_connect($db_host, $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 3";
- $query_result = mysql_query($query);
- $num_rows = mysql_numrows($query_result);
- //close database connection
- mysql_close();
- // html page starts after
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- ...
- //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 %#d %Y", $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="post"></div>
- <br />
- <span class="date"> <?php echo $blog_date; ?>:</span> | <?php echo '<a href="'. $blog_permalink .'">'; ?><?php echo $blog_title; ?></a><br />
- <br />
- <?php echo $blog_content; ?> <br /><br />
- <?php
- } //end the for loop
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement