【发布时间】:2023-04-02 01:31:02
【问题描述】:
以下循环运行成功,并且在我的编辑器中没有显示语法错误,但它只破坏了它之后的高级自定义字段 PHP(之前的所有 ACF 都可以正常工作,除了 ACF 之后的所有内容都可以正常工作)。
<?php
$args=array(
'post_type' => 'page',
'post_parent' => '39'
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="project" style="background-image:url('<?php the_field('preview_thumbnail'); ?>')">
<div class="project-overlay" style="background-color:<?php the_field('project_highlight_color'); ?>">
</div>
<div class="project-content">
<h3><?php the_title(); ?></h3>
<p><?php the_field('preview_text'); ?></p>
<a href="<?php the_permalink(); ?>" class="button arrow-right">Read more</a>
</div>
</div>
<?php endwhile; } ?>
这是一个在它之后仍然有效的示例<img src="<?php echo get_template_directory_uri(); ?>/images/logo-white.png" />
下面是一个例子,说明它之后的问题(高级自定义字段代码)<p class="banner-text"><?php the_field('pullout_summary'); ?></p>
抱歉,如果这是一个公然的修复!提前致谢。
【问题讨论】:
-
没什么明显的,但你所说的休息是什么意思?我假设它的 html 错误?如果是,您应该检查 html 输出以查看正在输出的内容。
-
好问题。它什么也不显示。因此,在我帖子最底部的代码行(pullout_summary)中,p 标签中没有显示任何内容。这就像 ACF 到达循环的结尾并停止尝试页面的其余部分。
标签: wordpress while-loop syntax-error advanced-custom-fields