foreach ($postslist as $my_post) :
setup_postdata($my_post);
$my_year = substr($my_post->post_date, 0, 4);
$my_month = substr($my_post->post_date, 5, 2);
$my_day = substr($my_post->post_date, 8, 2);
$my_time = date('Y年m月d日', mktime(0,0,0,$my_month,$my_day,$my_year));
$my_permalink = get_permalink($my_post->ID);
$my_title = $my_post->post_title;
$rep_contents .= "\t<li>»" . $my_time . "<br /><a href=\"" . $my_permalink . "\">" . $my_title . "</a></li>\n";
endforeach;
必用なpostデータを取得してforeachまではできているので、foreachして取り出したpostのデータを表示することが重要です。
現状のソースですとthe_title()などのようにその場で表示しようとしています。
取り出したpostデータから情報を抽出するには$my_post->post_titleなどのようにします。そのまま表示してもいいですが、上記ソースでは一度別の変数に格納しています。
これをfunctions.phpに記述するとなると、例えば、
function my_five_post_list($contents) {
if( is_page() && substr_count($contents, '[my_five_post_list]') != 0 ) {
$rep_contents = "\n<ul>\n";
$postslist = get_posts('orderby=post_date');
foreach ($postslist as $my_post) :
setup_postdata($my_post);
$my_year = substr($my_post->post_date, 0, 4);
$my_month = substr($my_post->post_date, 5, 2);
$my_day = substr($my_post->post_date, 8, 2);
$my_time = date('Y年m月d日', mktime(0,0,0,$my_month,$my_day,$my_year));
$my_permalink = get_permalink($my_post->ID);
$my_title = $my_post->post_title;
$rep_contents .= "\t<li>»" . $my_time . "<br /><a href=\"" . $my_permalink . "\">" . $my_title . "</a></li>\n";
endforeach;
$rep_contents .= "</ul>\n";
$new_contents = str_replace('[my_five_post_list]', $rep_contents, $contents);
} else {
$new_contents = $contents;
}
return $new_contents;
}
add_filter('the_content', 'my_five_post_list');
などのようになるでしょうか。
ページの表示したい任意の場所に[my_five_post_list]を記述することでその部分を書き換えます。
適当な作りなのでご参考までにおねがいします;)