Archive for August 16th, 2006

16
Aug
06

List WordPress post titles, etc. outside of WordPress

There are probably many mentions of how to do this around the web and forums, but I couldn’t quickly find any code samples so I came up with my own by hacking the RSS templates. Using this snippet you can list post titles, even exceprts or comments outside of WordPress on your website without having to go through the web interface.

It’s as simple as creating a new PHP file. ie. newest.php in your wordpress root (topmost folder) and then including it in any other file on your website that is outside of wordpress with:

<? @include ($_SERVER['DOCUMENT_ROOT'].'/wordpress/newest.php'); ?>

Here’s the code for “newest.php”

<?php $limit=6; $more=1; $count=1;

if (empty($wp)) {require_once('wp-config.php'); wp('feed=rss');}

if ($posts) { foreach ($posts as $post) { start_wp(); ?>

<a href="<?php permalink_single_rss() ?>" /><?php the_title_rss() ?></a><br>

<?php $count++; if ($count > $limit) { break; } } } ?>

That will list the latest post titles, up to limit you set (I chose 6).
It’s easy to add excerpts, etc to that code if you study the rss & rss comments templates.




c

Blog Stats

  • 63,488 hits

 

August 2006
S M T W T F S
    Feb »
 12345
6789101112
13141516171819
20212223242526
2728293031