archive.phpでアーカイブページを作成しています。
表示するアーカイブは通常の「post」になります。
以下のコードで一覧の表示は出来ました。
<ul> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li><span><?php the_time('Y/m/d') ?></span><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; endif; ?> </ul>
この際の表示は
・2019/月/日 タイトルタイトル
・2019/月/日 タイトルタイトル
・2019/月/日 タイトルタイトル
となりました。
これに特定のカテゴリを指定して表示しようと思い。
<?php $arg = array( 'category_name' => 'スラッグ名1' ); <ul> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li><span><?php the_time('Y/m/d') ?></span><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; endif; ?> </ul> <?php $arg = array( 'category_name' => 'スラッグ名2 ); <ul> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li><span><?php the_time('Y/m/d') ?></span><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; endif; ?> </ul>
と書いたら
スラッグ1の表示
・2019/月/日 タイトルタイトル
・2018/月/日 タイトルタイトル
・2017/月/日 タイトルタイトル
スラッグ2の表示
・2019/月/日 タイトルタイトル
・2018/月/日 タイトルタイトル
・2017/月/日 タイトルタイトル
なってしまい、スラッグごとの全ての年度が表示されてしまいます。
理想は
スラッグ1の表示
・2019/月/日 タイトルタイトル
・2019/月/日 タイトルタイトル
・2019/月/日 タイトルタイトル
スラッグ2の表示
・2019/月/日 タイトルタイトル
・2019/月/日 タイトルタイトル
・2019/月/日 タイトルタイトル
としたいです。
対策がわかれば、ご教示のほどよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー