Wordpressで著者が複数人いた場合に著者名を記事毎に変えたいのですが、
プラグインを使わずに記事毎に著者名を変えて表示する方法はありますでしょうか?
ユーザーの追加で追加した日本語の名前を使いたいです。
<span class="writeName"><?php the_author(); ?></span>
このようにただ単に著者名を表示する方法はわかりました。
テーマはtwentyseventeenを使っています。
下記は新着情報の一覧と著者名、カテゴリー名、記事のタイトル、サムネイルを表示する物です。
ここの著者名をユーザーの追加で追加した名前を使って記事ごとに著者名を変えたいのです。
例えばユーザー追加したAさんが○○という記事を書いたら著者名のところをAさんにBさんが□□という記事を
書いた記事ならBさんにとしたいのです。
<!-- 新着記事表示 --> <?php $args = array( 'posts_per_page' => 14 // 表示件数の指定 ); $posts = get_posts( $args ); foreach ( $posts as $post ): // ループの開始 setup_postdata( $post ); // 記事データの取得 ?> <!-- カテゴリー名取得 --> <?php $category = get_the_category(); $cat_id = $category[0]->cat_ID; $cat_name = $category[0]->cat_name; $cat_slug = $category[0]->category_nicename; ?> <!-- カテゴリー名取得 --> <!-- imgTextBox --> <div class="imgTextBox"> <p class="textP"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br><span class="postDate"><?php echo get_the_date( $format, $post ); ?></span><span class="writeName"><?php the_author(); ?></span><span class="catName"><?php echo $cat_name; ?></span></p> <p class="imgP"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a></p> </div> <!-- imgTextBox --> <?php endforeach; // ループの終了 wp_reset_postdata(); // 直前のクエリを復元する ?> <!-- 新着記事表示 -->
試したこと
<?php if ( is_singular() && get_the_author_meta( 'description' ) && is_multi_author() ) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?> <div class="author-info"> <div class="author-description"> <h3><?php the_author(); ?>について</h3> <div class="author-avatar"> <?php $author_bio_avatar_size = apply_filters( 'twentytwelve_author_bio_avatar_size', 68 ); echo get_avatar( get_the_author_meta( 'user_email' ), $author_bio_avatar_size ); ?> </div><!-- .author-avatar --> <p><?php the_author_meta( 'description' ); ?></p> <div class="author-link"> <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author"> <?php the_author(); ?>の全ての投稿を表示する </a> </div><!-- .author-link --> </div><!-- .author-description --> </div><!-- .author-info --> <?php endif; ?>
こちらを試してみましたが何も表示されませんでした。
回答1件
あなたの回答
tips
プレビュー