WoardPress でCMSもどき。
トップページに部分的に呼びたいときに、つーか1ページに二個表示とか?
まず、普通にインスト
次、
wp-content/themes/default に
page-newsXML.php とか適当に名前付けてアップ。
中身例
<?php header(‘Content-Type: text/xml; charset=’.get_option(‘blog_charset’), true); ?>
<?php /*
Template Name: newsXML
*/ ?>
<?php echo ‘<?xml version=”1.0″ encoding=”‘.get_option(‘blog_charset’).’”?’.’>’; ?>
<root>
<?php query_posts(“posts_per_page=5&category_name=’news’”); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<item>
<pubdate><?php echo get_post_time(‘Y-m-d H:i:s’, true); ?></pubdate>
<?php the_category_rss(); ?>
<description><![CDATA[<?php the_content(__(‘Read the rest of this entry »’, ‘kubrick’)); ?>]]></description>
</item>
<?php endwhile; endif; ?>
</root>
そんで、管理画面で新規ページ作成
タイトルをpage-newsXMLとかにして、テンプレートをnewsXMLにする。
newsXMLってのは上の例の
Template Name: newsXML
の部分なのです。
あとは公開して、パーマリンクをクリックすると完成。
さらにPHPそのXMLを読み込んで表示するにはこんなかんじ
<?php
#Simple_XMLでの実装
$base_url = “http://www.lessthan.tv/news/newsxml”;
#データ取得
$xml = simplexml_load_file($base_url);
foreach ($xml->item as $item) {
//UTCを数字に
$time = strtotime($item->pubdate);
//グリニッジにする
$time = date(‘Y.m.d’,$time);
#出力
print <<< OUT_END
<div>
<p>$time</p>
<div></div>
<h2>$item->title</h2>
<div></div>
<p>
$item->description
</p>
</div>
OUT_END;
}
?>
でOK