yStandardの記事カードに著者アバターと著者名を表示させるカスタマイズ

yStandardのカスタマイズについて書きます。

通常は記事カードに著者の出力はないのですが、フックを使って著者表示させてみました。

add_action( 'ys_archive_detail_append', 'add_author_info_to_archive_card' );
function add_author_info_to_archive_card() {
    $author_id = get_the_author_meta( 'ID' );
    $author_avatar = get_avatar( $author_id, 32, '', '', [ 'class' => 'c-author-avatar' ] );
    $author_name = get_the_author();

    echo '<div class="c-author-info">';
    echo $author_avatar;
    echo '<span class="c-author-name">' . esc_html( $author_name ) . '</span>';
    echo '</div>';
}

ys_archive_detail_appendに差し込んだだけです。

あとはCSSで整えればOKです!

高速・安心のWebサイト運営なら
Hostingerで決まり!

WordPressも秒速でインストール。高性能・低価格で、個人からビジネスまで幅広く対応します。

公式サイトを見る

Author