Display 5 latest Wordpress posts


/ Published in: PHP
Save to your folder(s)

Grab 5 latest Wordpress posts and display them on a non-Wordpress PHP page.


Copy this code and paste it in your HTML
  1. <?php
  2. // Include Wordpress
  3. define('WP_USE_THEMES', false);
  4. require('./blog/wp-blog-header.php');
  5. query_posts('showposts=5');
  6. ?>
  7.  
  8. <ul>
  9. <?php while (have_posts()): the_post(); ?>
  10. <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  11. <?php endwhile; ?>
  12. </ul>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.