[英]Wordpress Single.php advanced custom fields loop
我有一些高级自定义字段页面,它们都使用转发器字段具有相同的结构。 我希望他们所有人共享同一个single.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
从WordPress Codex:
single- {post_type} .php如果您的自定义帖子类型是'product',和/或query_var =“ product”,则WordPress将寻找single-product.php以显示帖子的单个或永久链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.