最近コメントの付いた、投稿へのリンク一覧表示
<?php
/**
* コメントの付いた、投稿一覧を表示
*
* テンプレートへ、記述してください
*
*/
$pfx_comments= get_comments('type=comment&status=approve&number=10');
if ( is_array( $pfx_comments ) and ! empty( $pfx_comments ) ) {
$pfx_author= "---";
$pfx_html= '<li class="comments-post"><a href="%1$s">%2$s</a>&nbsp;
<span class="%6$s">%7$s</span>&nbsp;<span class="%3$s"><a href="%4$s">%5$s</a></span>';
foreach($pfx_comments as $pfx_comment){
$pfx_comment_post= get_post($pfx_comment->comment_post_ID);
$pfx_post_title= $pfx_comment_post->post_title;
$pfx_permalink= get_permalink($pfx_comment->comment_post_ID);
$pfx_comment_author_link= get_permalink($pfx_comment->comment_post_ID)."#comment-".$pfx_comment->comment_ID;
if( isset( $pfx_comment->comment_author ) and !empty( $pfx_comment->comment_author) ) {
$pfx_author= $pfx_comment->comment_author;
}
$pfx_comment_date= preg_replace( ' |[^0-9A-z]+ |','-', $pfx_comment->comment_date );
$pfx_comment_date= str_replace( array('am','pm','AM','PM'),'', $pfx_comment_date );
$pfx_comment_date= sprintf('%1$s前', human_time_diff( strtotime( $pfx_comment_date ) , time() + 32400 ) );
printf( $pfx_html,
esc_url( $pfx_permalink ),
esc_html( $pfx_post_title ),
'comment-author',
esc_url( $pfx_comment_author_link ),
esc_html( $pfx_author ),
'comment-date',
esc_html( $pfx_comment_date )
);
}
}
?>
20130409
$pfx_comment_date 時刻の取得方法を変更
時刻を、preg_replaceしているのは、英語表記対象で、時刻が日本語になっていると、strtotime()は、うまく動かない am pmも同じ理由
strtotime() が 9時間ずれるのがよくわからない
human_time_diff()で9時間分を補正しています。
