任何人都知道为什么这个计数器不会计入h4标签的id?
<?php
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
//Do something if a specific array value exists within a post
$clauses = wp_get_post_terms($post->ID, $section->taxonomy, array("fields" => "all"));
$counter3 = 0;
foreach($clauses as $clause) { ?>
<h4 class="<?=($clause->parent == 0) ? 'd-none' : '' ?>" id="<?php echo $counter3; ?>"><?php echo $clause->name; ?></h4>
<a class="d-block" href="<?php echo the_permalink();?>"><?php echo the_title(); ?></a>
<?php $counter3++; }?>
<?php endwhile; endif; wp_reset_query(); ?>
任何帮助表示感谢。
CHRIS
答案 0 :(得分:0)
请放
$counter3 = 0;
在循环开始之前;
代码应该是这样的:
<?php
if ( $loop->have_posts() ) :
$counter3 = 0;
while ( $loop->have_posts() ) : $loop->the_post();
//Do something if a specific array value exists within a post
$clauses = wp_get_post_terms($post->ID, $section->taxonomy, array("fields" => "all"));
foreach($clauses as $clause) { ?>
<h4 class="<?=($clause->parent == 0) ? 'd-none' : '' ?>" id="<?php echo $counter3; ?>"><?php echo $clause->name; ?></h4>
<a class="d-block" href="<?php echo the_permalink();?>"><?php echo the_title(); ?></a>
<?php $counter3++; }?>
<?php endwhile; endif; wp_reset_query(); ?>