前提・実現したいこと
Wordpress初心者です。
VT Grid Magと言うテーマを使い、Webページを作成しようとしているのですが
デフォルトではTOPページに投稿の一覧がグリッド状に表示される様になっています。
ここに特定のカテゴリ(id=15 スラッグ"new")を表示したいと考えています。
発生している問題・エラーメッセージ
topページで読み込んでいるテンプレートがindex.phpだったので、色々と書き換えてみたのですがうまくいきません。
php
1/**元のコード**/ 2<?php 3 if( have_posts() ) { 4 5 // Post Wrap. 6 if( 'layout-default' != $layout ) { 7 echo '<div class="post-container">'; 8 } 9 10 // Start the Loop. 11 while( have_posts() ) { 12 the_post(); 13 14 // Include template for the content. 15 if( 'layout-default' != $layout ) { 16 get_template_part( 'content', 'grid' ); 17 } 18 else { 19 get_template_part( 'content', get_post_format() ); 20 } 21 } 22 23 // End Post Wrap. 24 if( 'layout-default' != $layout ) { 25 echo '</div>'; 26 } 27 28 // Pagination. 29 the_posts_pagination(); 30 31 } 32 else { 33 // Not Found Template. 34 get_template_part( 'content', 'none' ); 35 } 36?>
試したこと
ネットで調べたのですが、ぴったりの情報がなく、汎用的な内容のページから
カテゴリリンクはarchive.phpが読み込まれていたので、archive-15.phpを作成してみたり、
index.phpの条件を以下の通り変更してみたりしましたが、正常に動作しません。
※以下のコードにすると、そのカテゴリ以外でも表示されたり、求めている動作にはなりませんでした。
php
1/**試したコード**/ 2<?php 3 if(in_category(array(15))) { 4 5 // Post Wrap. 6 if( 'layout-default' != $layout ) { 7 echo '<div class="post-container">'; 8 } 9 10 // Start the Loop. 11 while(in_category(array(15))) { 12 the_post(); 13 14 // Include template for the content. 15 if( 'layout-default' != $layout ) { 16 get_template_part( 'content', 'grid' ); 17 } 18 else { 19 get_template_part( 'content', get_post_format() ); 20 } 21 } 22 23 // End Post Wrap. 24 if( 'layout-default' != $layout ) { 25 echo '</div>'; 26 } 27 28 // Pagination. 29 the_posts_pagination(); 30 31 } 32 else { 33 // Not Found Template. 34 get_template_part( 'content', 'none' ); 35 } 36?>
見当違いな事をしているかもしれませんが、ご教示頂けますと幸いです。
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/08 03:18