wp-load.phpをロードすれば、WordPress のタグが使える

wp-load.phpをロードすれば、WordPress のタグが使えるということなので、試してみました。

例えば、http://example.jp が、/var/www/html に対応しているとします。ここで、/var/www/html/wordpress という名前でwordpressをインストールしたとします。後は、/var/www/html/sample.php として下記のファイルをおき、http://example.jp/sample.php へアクセスします。

<?php require('./wordpress/wp-load.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
<head><title>wp-load.phpの利用方法</title></head>
<body>
<ul>
<?php
$posts = get_posts("numberposts=5&category=&orderby=post_date&offset=0");
foreach ($posts as $post):
  setup_postdata($post);
?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php 
endforeach; 
?>
</ul>
</body></html>

無事、WordPressのエントリ一覧を5つ表示できたらOKです。

WordPress 3.0 関連書籍:

同じタグの記事: WordPress
同じカテゴリの記事: General
関連書籍: WordPress