WordPressでカスタム投稿タイプに、子階層の共通テンプレートを作るにはどうしたらいいでしょうか?
###前提
1.カスタム投稿タイプ「material」をregister_post_type
で自作しました。
2.記事を投稿すると次のようなURLになります。
http://example.com/material/10
http://example.com/material/11
3.テンプレートは「material.php」で、そこに次のようなタブを作ってます。
html
1<div> 2 <label><a href="<?php the_permalink(); ?>/taste">taste</label> 3 <label><a href="<?php the_permalink(); ?>/color">color</label> 4</div>
###実現したいこと
こうして作られる「10」や「11」の記事に、タブに合わせて次のような子階層を持たせたいと考えています。
http://example.com/material/10/taste
http://example.com/material/10/color
http://example.com/material/11/taste
http://example.com/material/11/color
「10」や「11」の記事にあるタブをクリックすると、URLにスラッシュ区切りで「/taste」や「/color」を追加したいのですが、
このような子階層はどうやって作るのでしょうか?
イメージとしては、「material.php」のタブをクリックしたときに子階層として、「taste.php」や「color.php」のテンプレートを表示したい感じ?でしょうか。
###試したこと
register_post_type
に
'supports' => array( 'page-attributes' ),
'hierarchical' => true,
と書いたのですが、これでは「material」同士を親子階層に繋げられるだけ?のようでした。
「taste.php」のテンプレートと「color.php」のテンプレートを作って、「material.php」の子として使うためには、どうすればいいでしょうか?
あなたの回答
tips
プレビュー