wordpressの投稿(カテゴリ指定)で静的htmlの表示の記述方法
(ここに質問の内容を詳しく書いてください。)
宜敷くお願いいたします。
色々なサイトを参考に静的htmlにWPの投稿をインポート出来たのですが、
投稿カテゴリ全てでなく限定のカテゴリ、例えばNWESカテゴリのみ
読み込みたいのです。
色々試してみたのですが(PHPは初心者で)うまく出来ません。
どのようなコードをセットすれば良いか、ご教授ください。
該当のソースコードは以下なります。
<div class="wp-section-box"> <?php $args = array( 'posts_per_page' => 12, 'paged' => $paged, 'post_type' => array( 'post',),); $the_query = new WP_Query( $args ); ?> <ul> <?php if($the_query->have_posts()): ?> <?php while($the_query->have_posts()) : $the_query->the_post(); ?> <?php $category = get_the_category(); $cat_name = $category[ 0 ]->cat_name; $cat_slug = $category[ 0 ]->category_nicename; ?> <li class="titleWrap"> <a href="<?php the_permalink(); ?>" class="toumei"> <?php if (has_post_thumbnail() ) { echo get_the_post_thumbnail($post->ID, 'medium'); } else { $thumbimg = content_url(); echo '<img src="'.$thumbimg.'/uploads/sample.png">'; } ?> </a> <!--カテゴリ--> <p class="titlelist"><span class="cat <?php echo $cat_slug; ?>"> <?php echo $cat_name; ?>:</span> <?php the_time( get_option( 'date_format' ) ); ?> <span class="title"><a href="<?php the_permalink(); ?>" class="wptitle toumei"><br /> <!--タイトル--> <?php echo get_the_title(); ?></a></span> <span class="date"></span> </p> <!--記事部分--> <p class="wptext"> <?php if ( mb_strlen( $post->post_content, 'UTF-8' ) > 150 ) { $content = str_replace( '\n', '', mb_substr( strip_tags( $post->post_content ), 0, 150, 'UTF-8' ) ); echo $content . '…'; } else { echo str_replace( '\n', '', strip_tags( $post->post_content ) ); } ?> </p> </li> <?php endwhile; endif; ?> </ul> <?php wp_reset_postdata(); ?> </div>試したこと
<?php if(is_category('news')) : ?>などの分岐や、その他です・・・以上宜敷くお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/09 01:15