[WP]WordPress Popular Postsをカスタマイズする

この記事は約3分で読めます。

WordPressで人気記事一覧を表示するプラグイン”Wordpress Popular Posts”を使用したサイトで、表示をカスタマイズするのにフィルターフックを使えるということで調べてみた。

今回はwpp_postを使った。

functions.phpに以下のコードを記述。

function custom_single_popular_post( $content, $p, $instance ){
$thumb_id = get_post_thumbnail_id( $p->id);
$img = wp_get_attachment_image_src( $thumb_id, 'thumbnail' );
$output = '<li><a href="' . get_the_permalink( $p->id ) . '" title="' . esc_attr($p->title) . '"><span class="num"></span><span class="box"><span class="img"><img src="'. $img[0].'" title="' . esc_attr($p->title) . '" width="100" height="100"></span><span class="title"><strong>' . $p->title . '</strong></span></span></a></li>';
     return $output;
}
add_filter( 'wpp_post', 'custom_single_popular_post', 10, 3 );

 

 

 

$outputで表示したいように書けば自由にカスタマイズができる♪

タイトルとURLをコピーしました