WordPress

関連記事の表示(著者別)

更新日:2026-05-04 著者:unigram 読了目安:1分

著者を指定して関連記事を表示する方法

<h2 class="author_head"><?php the_author(); ?>の投稿一覧</span></h2>
<?php
        $args = array(
            'author_name' => 'kawagoe_cafe',//著者名
            'posts_per_page' => 10,
        );
        $the_query = new WP_Query($args);
        ?>
        <?php if ($the_query->have_posts()) : ?>
            <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>


			<!-- ここに記事コンテンツ -->
			<div class="post">
    				<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
    				<h3 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
			</div>



<?php endwhile; ?>
<?php else : ?>
<?php endif; wp_reset_postdata(); ?> 

この記事を書いた人

unigram
web、印刷、映像などの制作をしています。@京都、フリーランス18年目。 大学で講師もしています。 自身の備忘録も兼ねて、Web制作・WordPress・SEO・GA4・生成AI活用をテーマに情報発信しています。わかりやすく優しい内容で記事作成を心がけています。