Sunday, June 7, 2009

Show the last x number of posts on Wordpress in PHP

This code shows the last x-number of posts (15 in this example) in your wordpress blog. Make sure you put in the proper directory in the ‘require()’  string. This code can be on a completely seperate page, fully outside of wordpress

<?php
// Include Wordpress
define('WP_USE_THEMES', false);
require('./wordpress/wp-blog-header.php');
query_posts('showposts=15');
?>

<ul>
<?php while (have_posts()): the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>

No comments:

Post a Comment