php高级自定义字段循环


Wordpress Single.php advanced custom fields loop

我有几个高级自定义字段页面,它们都使用重复字段具有相同的结构。我希望它们都共享同一个。php文件。(我相信应该没问题?)

所有我的php是在正确的顺序,因为它的工作很好,当我添加这个上面,如果有帖子:

    <?php
    // The Query
    $args = array(
      'post_type' => 'chemicals'
      );
    $the_query = new WP_Query( $args );
    ?>

但是一旦它被删除,它就不会得到帖子信息。也许我的php结构有问题?我很新的PHP和wordpress所以任何帮助将是伟大的。

    <div class="section group">
    <div class="col span_3_of_12">
    <?php wp_nav_menu(
    array(
    'menu'            => 'consumables',
    'container'       => 'div',
    'container_class' => 'product-menu',
    'menu_class'      => 'product-menu',
    )); ?>
    </div>

        <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                <?php if( have_rows('product') ): ?>
                    <div class="col span_3_of_12">
                        <?php while( have_rows('product') ): the_row(); 
                            // vars
                            $title = get_sub_field('product_title');
                            $thumbnail = get_sub_field('thumbnail');
                            $blurb = get_sub_field('main_blurb');
                            $technical = get_sub_field('technical');
                            $description = get_sub_field('description');
                            ?>
                            <a href""><img class="open-image" src="<?php echo $thumbnail; ?>"></a>
                    </div>
                    <div class="col span_6_of_12">
                            <div class="product-details">
                                <h4><?php echo $title; ?></h4>
                                <p><?php echo $blurb; ?></p>
                            </div>
                            <div class="product-tech">
                                <div class="technical">
                                    <h5>Technical</h5>
                                    <p><?php echo $technical; ?></p>
                                </div>
                                <div class="technical">
                                    <h5>Description</h5>
                                    <p><?php echo $description; ?></p>
                                </div>
                            </div>
                        <?php endwhile; ?>
                    </div>
                <?php endif; ?>
        <?php endwhile; ?>
    <?php endif; ?>

我看到你的帖子是自定义的。模板的文件名应该是single-chemicals.php,而不是single.php

From WordPress codex:

single-{post_type}.php如果你的自定义帖子类型是'product',和/或query_var = "product", WordPress将查找php显示文章的单链接或永久链接。