我坚持这个问题,看起来很简单,但找不到解决它的方法。
我有这样的循环:
<div class="features-items__wrapper">
<h2><?php echo $currentTitle; ?></h2>
<?php
global $post;
$post_slug = $post->post_name;
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'feature\',
\'order\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'feature_сategory\',
\'field\' => \'slug\',
\'terms\' => $post_slug
)
)
);
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<?php
$counter = 0;
$total = $the_query->post_count;
while ( $the_query->have_posts() ) : $the_query->the_post();
if ($counter % 2 === 0) {
?>
<div class="row">
<?php } ?>
<a href="<?php the_permalink(); ?>" class="features-items__item col-12 col-xl-6">
<div class="features-items__img">
<img src="<?php the_field(\'feature_item_icon\'); ?>" alt="">
</div>
<div class="features-items__description">
<h3><?php the_field(\'feature_item_title\'); ?></h3>
<?php the_field(\'hero_subtitle\'); ?>
</div>
</a>
<?php $counter++; if ($counter != 0 && ($counter % 2 === 0 || $counter === $total)) { ?>
</div>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
我得到了这样的结果:
https://prnt.sc/100lsjh 和makrup:
As you see markup is broken and it\'s because second feature has link inside (field hero_subtitle has WYSIWYG editor type)
最合适的回答,由SO网友:Buttered_Toast 整理而成
似乎您的某个ACF字段包含<a>
在其中添加标签。
在HTML中,不能有和<a>
标记在另一个内<a>
标签
检查ACF字段the_field(\'feature_item_title\')
和the_field(\'hero_subtitle\')
, 检查他们的内容,很可能会发现<a>
标记其中一个,然后将其删除,您的html将得到正确的结构