If you’re reading this on the Dev Cave Dlog page, then I’ve managed to integrate WordPress blog entries into a page outside the realm of the WordPress install. The primary resource was the WordPress Codex article on The Loop plus API reference for the query_posts() function. The following snippet could (should) certainly be made into a common parameterized function.

Soapbox: Note that I prefer to write code that is readable, rather than jumping in and out of php tags, interspersed with BASIC-esque syntax (endif… geesh).

<?php
if (file_exists("../../blog"))
{
    require_once("../../blog/wp-config.php");
    define('WP_USE_THEMES', false);
    query_posts('cat=4&showposts=5');
    if (have_posts())
    {
        while (have_posts())
        {
            the_post();
            echo "<div class='section'><h1>";
            the_title();
            echo "</h1><p>";
            the_time('F j, Y g:i a');
            echo "</p><p>";
            the_content();
            echo "</p></div>";
        }
    }
    else
    {
        echo "<p>No Dev Posts</p>";
    }
}
?>
Share and Enjoy:
  • StumbleUpon
  • Facebook
  • Twitter
  • Digg
  • del.icio.us
  • Reddit
  • Technorati
  • Google Bookmarks
  • Slashdot
  • N4G