情報を追記している場合はありますが、古い情報を訂正はしていませんので、公開年月日を参照してください。プラグイン・タグ、いずれもワードプレス・PHPのバージョン等によって動作しない場合もあります。
人気記事を表示するプラグインWordPress Popular Posts。CSSで順位を表示する方法はよく紹介されているが、支給されたHTMLに合わせる必要があったので、HTMLのカスタマイズにカウントを付けて表示させた。
function report_popular_posts_html_list( $mostpopular, $instance ){
$output = '<ul class="ranking">';
$count = 1; foreach( $mostpopular as $popular ) {
$output .= '<li><dl>' .PHP_EOL;
$output .= '<dt class="thumbnail_image"><a href="' . get_the_permalink( $popular->id ) . '">'. get_the_post_thumbnail( $popular->id, 'thumbnail' ) .'</a></dt>';
$output .= '<dd class="rankingno">'. $count .'</dd><dd class="rankingtitle"><a href="' . get_the_permalink( $popular->id ) . '">'. esc_html( $popular->title ) .'</a></dd>';
// タクソノミーを表示
$output .= '<dd class="rankingcate">'. get_the_term_list( $popular->id, 'report_category', '<div class="icon">', '</div><div class="icon">', '</div>' ) .'</dd>';
$output .= '</dl></li>' .PHP_EOL;
$count++; }
$output .= '</ul>';
return $output;
}
add_filter( 'wpp_custom_html', 'report_popular_posts_html_list', 10, 2 );