我正在使用高级自定义字段,并试图构建一个导航菜单,其中当前项目有一个额外的类,让他们知道自己在哪里。
The entire structure in question. It\'s using ACF repeater fields:
<?php if(get_field(\'main_nav\', 53)): ?>
<?php while(has_sub_field(\'main_nav\', 53)): ?>
<li><a
<?php
$link1 = the_permalink();
$link2 = the_sub_field(\'link_url\');
if ( $link1 == $link2 ) {?> class="s4-secondary-nav-current" <?php } ?>
href="<?php the_sub_field(\'link_url\'); ?>"><?php the_sub_field(\'link_text\'); ?></a></li>
<?php endwhile; ?>
<?php endif; ?>
Specific conditional:
<?php
$link1 = the_permalink();
$link2 = the_sub_field(\'link_url\');
if ( $link1 == $link2 ) { echo \'class="s4-secondary-nav-current"\'; } else {} ?>
似乎发生的是$link1和$link2只是在HTML中打印出来的。
Was also trying to do something like this that gets same results as above:
<?php if ( the_permalink() == the_sub_field(\'link_url\') ) {?> class="s4-secondary-nav-current" <?php } ?>