同じカスタム投稿の同じタームの記事を取得する方法です。
アーカイブページ以外でpage.phpなどに表示させることが可能です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php global $post; $term = array_shift(get_the_terms($post->ID, 'タクソノミー名')); $args = array( 'numberposts' => 5, //(8件表示の場合) 'post_type' => 'カスタム投稿タイプ名', //カスタム投稿タイプ名 'taxonomy' => 'タクソノミー名', //タクソノミー名 'term' => $term->slug, //ターム名 'post__not_in' => array($post->ID) ); ?> <?php $myPosts = get_posts($args); if($myPosts) : ?> <?php foreach($myPosts as $post) : setup_postdata($post); ?> <p><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?><?php the_title(); ?></a></p> <?php endforeach; ?> <?php else : ?> <p>投稿が見つかりません</p> <?php endif; wp_reset_postdata(); ?> |
コメント