Posted By

jakepaint on 11/08/07


php wordpress blog dynamic posts

Versions (?)

dynamic list pulls most recent posts

 / Published in: PHP


I didn't write this, but I want to keep it for later. I don't remember where I got it: thank you, whoever wrote it!

  1. <?php
  2. $how_many=4; //How many posts do you want to show
  3. require_once("blog/wp-config.php"); // Change this for your path to wp-config.php file ?>
  5. <ul id="whats-new">
  6. <?
  7. $news=$wpdb->get_results("SELECT `ID`,`post_title` FROM $wpdb->posts
  8. WHERE `post_status`= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
  9. foreach($news as $np){
  10. printf ("<li><a href=\"blog/index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
  11. }?>
  12. </ul>

Report this snippet  

You need to login to post a comment.