最初と最後の記事へのリンクを出力するようにしました。
/*
* 最初と最後の記事のリンクを出力します
*/
function print_newest_post( $indent = 1 ) {
global $wpdb, $id;
$indentText = '';
for ( $i = 0; $i < $indent; $i ++ )
$indentText .= "\t";
$r = array( 'type' => 'postbypost', 'limit' => '1' );
$where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
$join = apply_filters( 'getarchives_join', "", $r );
$infos = array (
array( 'orderby' => 'post_date DESC ', 'linkrel' => 'last' ), // 最後の記事
array( 'orderby' => 'post_date ASC ', 'linkrel' => 'first' ) // 最初の記事
);
foreach( $infos as $info ) {
extract( $info );
$arcresults = $wpdb->get_results( "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby LIMIT 1" );
if ( $arcresults ) {
$arcresult = $arcresults[0];
if( $arcresult->ID != $id ) {
echo $indentText. '<link rel="'. $linkrel. '" href="'. get_permalink($arcresult->ID). '" title="'. apply_filters('the_title', $arcresult->post_title, $arcresult). '" />'. "\n";
}
}
}
}
この関数を呼ぶ前に the_post を行ってください。そうでないとエントリーIDが取得できませんので(取得できなくても大した問題はありませんが)。 wp.Vicuna デフォルトでは body 要素の前で行っているのでそれを先頭にもってきてください。
wp_get_archives 関数を参考に作成しました。