ステージ(日にちの経過とともに、変化していく)別に投稿記事の一覧表示

ステージ(日にちの経過とともに、変化していく)別に投稿記事の一覧表示をさせたい。

下記のコードを考えましたが、表示がなされません。
どこが悪いのか、ご教示いただけませんでしょうか?
$statusClassというのは、WordPressのカテゴリーでもなく、
単に便宜上の分類名(変数)です。
けれど、single-product.phpからその変数を受け取っていないようで、
その分類の製品がないと判断されているようで、
それで表示されないとかんがえます。
もしかしたら、他の問題があるかもしれませんが、
single-product.phpからarchive-product.phpには変数を引き継ぐ方法を教えてください。

下記に考えたコードを書きます。

archive_products.php

<?php /* Template Name: 製品一覧 */ ?> <?php get_header(); ?> <?php if($statusClass == 'a_group'): ?> <section> <?php $paged = (int)get_query_var('paged'); $args = array( 'posts_per_page' => 10, 'oreder' => 'DESC', 'post_type' => 'post' ); $the_query = new WP_Query($args); if ( $the_query->have_posts() ): ?> <div> <h2>A_group</h2> <div></div> <?php while ( $the_query->gave_posts() ) : $the_query->the_post(); ?> <div> A製品の説明</div> <?php endwhile; ?> <?php endif; ?> </div> </section> <?php elseif($statusClass == 'b_group'): ?> <section> <?php $paged = (int)get_query_var('paged'); $args = array( 'posts_per_page' => 10, 'oreder' => 'DESC', 'post_type' => 'post' ); $the_query = new WP_Query($args); if ( $the_query->have_posts() ): ?> <div> <h2>B_group</h2> <div></div> <?php while ( $the_query->gave_posts() ) : $the_query->the_post(); ?> <div> B製品の説明</div> <?php endwhile; ?> <?php endif; ?> </div> </section> <?php else: ?> <section> <?php $paged = (int)get_query_var('paged'); $args = array( 'posts_per_page' => 10, 'oreder' => 'DESC', 'post_type' => 'post' ); $the_query = new WP_Query($args); if ( $the_query->have_posts() ): ?> <div> <h2>C_group</h2> <div></div> <?php while ( $the_query->gave_posts() ) : $the_query->the_post(); ?> <div> C製品の説明</div> <?php endwhile; ?> <?php endif; ?> </div> </section> <?php endif; ?> <?php get_footer();

上記のコードの中の「$statusClass」という変数はsingle-product.phpから来ています。
(single-product.php は表示されています。)

single

<?php /* Template Name: product投稿ページのテンプレート Template Post Type: post,product */ ?> <?php get_header(); ?> <hr> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <section <?php post_class(); ?>> <h2 class="section-title"><?php the_title(); ?></h2> <div class="product-top"> <div><?php the_field('name'); ?></div> <div class="status-explanation"> <?php date_default_timezone_set("Asia/Tokyo"); ?> <?php $opestart_string = get_field('opestart'); $opestart_string = str_replace('日', '', $opestart_string); $opestart_string = str_replace('月', '-', $opestart_string); $opestart_string = str_replace('年', '-', $opestart_string); $opestart_date = new DateTime($opestart_string); $opestart_number = strtotime($opestart_string); $opeend_string = get_field('opeend'); $opeend_string = str_replace('日', '', $opeend_string); $opeend_string = str_replace('月', '-', $opeend_string); $opeend_string = str_replace('年', '-', $opeend_string); $opeend_date = new DateTime($opeend_string); $opeend_number = strtotime($opeend_string); $returnday_string = get_field('returnday'); $returnday_string = str_replace('日', '', $returnday_string); $returnday_string = str_replace('月', '-', $returnday_string); $returnday_string = str_replace('年', '-', $returnday_string); $returnday_date = new DateTime($returnday_string); $returnday_number = strtotime($returnday_string); $today_date = new DateTime(date('Y-m-d')); $today_number = strtotime('today'); ?> <?php if($today_number < $opestart_number): $statusClass = 'a_group'; elseif(($opestart_number <= $today_number) && ($today_number < $opeend_number)): $statusClass = 'b_group'; else: $statusClass = 'c_group'; endif; ?> <?php if($statusClass == 'a_group'):?> <span class="before_operation"> A製品 </span> <?php elseif($statusClass == 'b_group'):?> <span class="under_operation"> B製品 </span> <?php else:?> <span class="c_group"> C製品 </span> <?php endif; ?> </div> </div> </section> <?php endwhile; // 繰り返し終了 ?> <?php else : //条件分岐:投稿が無い場合は ?> <?php endif; //条件分岐終了 ?> <?php get_footer();

よろしくお願いいたします。

コメントを投稿

0 コメント