
<?php
include_once('./wp-load.php');

// パラメータ取得
$limit = (int) (isset($_GET['limit']) && is_numeric($_GET['limit']) ? $_GET['limit'] : 5 );
$callback = wp_specialchars(attribute_escape(isset($_GET['callback']) ? $_GET['callback'] : 'callback'));
$charset = get_bloginfo('charset');
 
query_posts("showposts=$limit");        // 最終 $limit エントリ取得のループをつくる
if ( have_posts() ) {
    $out = null;
 
    // 最終 $limit エントリのタイトル・URL・日付を取得する
    while ( have_posts() ) {
        the_post();
        $out .= ( !empty($out) ? ',' : '');
        $out .= '{';
								$out .= '"title":"' . get_the_title() . '"';
        $out .= ',"link":"' . get_permalink() . '"';
        $out .= ',"pubdate":"' . the_date('Y/m/d','',' ： ',false) . '"';
// 							$out .= '"name":"' .  the_author_meta('nickname') . '"';
        $out .= '}';
    }
 
    // JSONP 形式で書き出す
    nocache_headers();
    header("Content-Type: application/x-javascript; charset=$charset");
    echo "$callback([$out]);";
 
} else {
    // 無ければ 404 Not Found を返す
    header("HTTP/1.0 404 Not Found");
    wp_die("404 Not Found");
}
?>