WordPress Hack for Slim Pages

Here's the PHP file I use to generate my slim page. It's called wp-slim.php and lives in the same directory as index.php.

<?php
if (!isset($feed)) {
    $blog = 1;
    $doing_rss = 1;
    require('wp-blog-header.php');
}
$more = 1;
$charset = get_settings('blog_charset');
if (!$charset) $charset = 'UTF-8';
header('Content-type: text/html', true);

?>
<?php echo '<?xml version="1.0" encoding="' . $charset . '"?'.'>'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <base href="<?php bloginfo_rss('url') ?>"/>
    <title><?php bloginfo_rss('name') ?></title>
    <meta name="author" content="Ian Davis" />
    <meta name="copyright" content="Copyright (c) 1999-<?php _e(gmdate("Y")) ?> Ian Davis" />
    <meta name="description" content="<?php bloginfo_rss("description") ?>" />
  </head>
  <body>
    <?php $items_count = 0; if ($posts) { foreach ($posts as $post) { start_wp(); ?>
    <div class="entry" id="entry<?php _e($post->ID) ?>">
      <h1><a href="<?php permalink_single_rss() ?>"><?php the_title_rss() ?></a></h1>
<?php if (get_settings('rss_use_excerpt')) : ?>
      <div class="content"><?php the_excerpt_rss(get_settings('rss_excerpt_length'), 2) ?></div>
<?php else : ?>
      <div class="content"><?php the_content('', 0, '') ?></div>
<?php endif; ?>

    </div>
    <?php $items_count++; if (($items_count == get_settings('posts_per_rss')) && empty($m)) { break; } } } ?>
  </body>
</html>

I also changed wp-feed.php to dispatch requests for slim pages (additions in green):

case 'rss2':
        require('wp-rss2.php');
        break;
    case 'slim':
        require('wp-slim.php');
        break;
    }
}

I changed the rewrite rule in my .htaccess to map index.slim to wp-feed.php:

RewriteRule ^index.(feed|rdf|rss|rss2|atom|slim)$ /2004/09/wordpress/wp-feed.php?feed=$1 [QSA]

Note: I'm not using the standard WordPress rewrite rule set. For backwards and future compatibility with other weblog systems I prefer to use file extensions for the various formats of a document.

Permalink: http://blog.iandavis.com/2004/09/wordpress-hack-for-slim-pages/

Other posts tagged as internet-alchemy, projects, syndication

Earlier Posts