Guest User

Untitled

a guest
Jun 21st, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2. # You will need to change these to reflect your actual wordpress database
  3. $dbhost = 'localhost' // This will probably be 'localhost' on your server
  4. $dbuser = 'username' // Your webhost will have given you this, and you will have used it in wordpress installation
  5. $dbpass = 'password' // Your webhost will have given you this, and you will have used it in wordpress installation
  6. $dbname = 'wordpress' // You will have decided this in wordpress installation
  7. $dbprefix = 'wp_' // You will have decided this in wordpress installation
  8.  
  9. # Connect to the database system as a whole
  10. $con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql (check your host, username and password)');
  11.  
  12. # Using the connection from above, select the wordpress database
  13. $con = mysql_select_db($dbname) or die ('Could not select database (are you sure the name is right?)');
  14.  
  15. # This query gets the 5 latest posts from the wordpress database
  16. $qry = mysql_query("SELECT * FROM ". $dbprefix ."posts ORDER BY post_date ASC LIMIT 5");
  17.  
  18. # For each post from the query above...
  19. while($row = mysql_fetch_assoc($qry))
  20. {
  21. # ... do this:
  22. echo 'Post title: ' . $row['post_title'] . '<br />';
  23. echo 'Post excerpt: ' . $row['post_excerpt'] . '<br /><br />';
  24. }
  25. ?>
Add Comment
Please, Sign In to add comment