サイト型アフィリエイトサイトを作る時に便利なのが固定ページの利用です。
Wordpressの固定ページにあるページ属性の親子関係を使うと、カテゴリーカテゴリ内の記事、という感じで階層ページを作ることができるのです。
このコードは親ページ用です。
<!--▽メインコンテンツ--> <div id="main-contents"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="post"> <h2 class="page-title"><?php the_title(); ?></h2> <div class="contents clearfix"> <div class="article"> <!--本文--> <?php the_content(); ?> <!--/本文--> </div> <!--/article--> <?php if(get_the_tags()){ ?> <div class="post-tag"> <p>タグ:<?php the_tags('', ', '); ?></p> </div> <?php } ?> </div> </div> <!--/post--> <?php endwhile; ?> <?php get_template_part('social-button'); wp_reset_postdata(); else : ?> <h2>お探しの記事は見つかりませんでした。</h2> <div class="contents"> <p>検索キーワードを変更し下記より再検索してください。</p><br /> <?php get_search_form(); ?> </div> <?php endif; ?> <?php $paged = (int) get_query_var('paged'); $args = array( 'posts_per_page' => 3, 'paged' => $paged, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'page', 'post_parent' => $post-> ID, 'post_status' => 'publish' ); $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"> <h2 class="post-title"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div class="contents clearfix"> <div class="article"> <!--アイキャッチ画像--> <?php if(has_post_thumbnail()){ ?> <div class="left"> <?php echo the_post_thumbnail(); ?> </div> <?php } ?> <!--/アイキャッチ画像--> <!--本文抜粋--> <?php the_excerpt(); ?> <p class="link-next"><a href="<?php the_permalink() ?>">「<?php echo(get_the_title('', '', false)); ?>」の続きを読む</a></p> <!--/本文抜粋--> </div> <!--/article--> </div> <!--/clearfix--> </div> <!--/post--> <?php endwhile; ?> <?php endif; ?> <?php if ($the_query->max_num_pages > 1) { echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%/', 'current' => max(1, $paged), 'total' => $the_query->max_num_pages )); } wp_reset_postdata(); ?> </div> <!--△メインコンテンツ-->
上記のコードは、親ページに書いた内容を表示させてその下に属する子ページ一覧を表示させるコードになっています。
'posts_per_page' => 3,
で子ページの表示件数を変更できます。
追記:
子ページを表示させるプラグインで使えそうなもの自分用メモ
- Child Pages Shortcode
- Shop Menu(ショップの商品を表示させるプラグイン)