前提・実現したいこと
archive.php内の条件分岐で、デフォルト投稿の一覧ページを表示したいと考えております。
wordpress2017にてサイトを作成中なのですが、投稿を二種類使用しています。
一つ目はデフォルト投稿(使用カテゴリはinfo)、二つ目はカスタム投稿(使用カテゴリはarea,event)です。
template-part/post内に「custum.php」という名前でアーカイブページのarticle部分を作成し表示はできました。
デフォルト投稿の一覧ページをtemplate-part/post内にもともとあったcontent.phpで表示させたいです。
archive.php内で条件分岐による振り分けは可能なのでしょうか??その際はどのように記述したらよいのでしょうか?
◆追記
現在のパーマリンク設定は、
「投稿名 http://localhost/wordpress/sample-post/」にチェックが入っており、カスタム構造の部分は「http://localhost/wordpress/%postname%/」となっております。
◆追記2
やはり上記のように条件分岐でcontent部分を振り分ける、というのはあまりやるべきではないのでしょうか?この質問をした理由なのですが、カスタム投稿に関連する部分を先に制作しておりまして、カスタム投稿の一覧をarchive.phpで表示させました。後からデフォルト投稿の一覧を作成しようと、archive-info.phpを作成したところarchive.phpで表示されてしまいました…
原因を探ったのですが分からず、content部分を条件分岐させてはどうだろう、という考えに至った次第です。
質問タイトルの通り、条件分岐についても引き続き教えて頂きたいですが、archive-info.phpで表示できなかった原因について思い当たる節などもありましたら教えて頂きたいです!
該当のソースコード
archive.php内コード(デフォルトの状態ですが念のため掲載します)
<div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php if ( have_posts() ) : ?> <?php /* Start the Loop */ while ( have_posts() ) : the_post(); /* * Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'template-parts/post/content', get_post_format() ); endwhile; the_posts_pagination( array( 'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>', 'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ), 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>', ) ); else : get_template_part( 'template-parts/post/content', 'none' ); endif; ?> </main><!-- #main --> </div><!-- #primary -->
回答3件
あなたの回答
tips
プレビュー