对不起,我只是PHP的一个新手
背景:此代码是三个滑块的循环,如您在此处看到的http://rashelectrical.com.au/。我只需要在第一张幻灯片上制作H1标签,然后制作另外两个H2标签
问题:
如何仅在第一个循环中将第二个循环和最后一个循环循环到H2和H1 循环吗?
谢谢
这是我的代码:
https://jsfiddle.net/4jm5vhbf/
<?php while(have_rows('banner_slider')) : the_row();?>
<div class="sl" >
<div class="header-content relative-block align-center text-center flex-container align-middle" style="background:url('<?php the_sub_field('image');?>') no-repeat">
<div class="row">
<div class="columns">
<div class="header-content-inner relative-block animate-children">
<h3><?php the_sub_field('subheading');?></h3>
<h1><?php the_sub_field('heading');?></h1>
<p><?php the_sub_field('description');?></p>
<div class="button-group align-center">
<?php $n = 1; while(have_rows('button_links')) : the_row();
$link_lr = get_sub_field('link');?>
<?php if($n == 2){
$n2 = 'hollow';
}else{
$n2 = '';
}?>
<a class="button <?php echo $n2; ?>" href="<?php echo $link_lr['url']; ?>"><span><?php echo $link_lr['title']; ?></span></a>
<?php $n++; endwhile;?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile;?>
答案 0 :(得分:0)
在看不到完整代码的情况下很难说出来,也许是类似的东西?
<!-- Instead of H3 tag here, use P tag with css class and change the font size with css -->
<h3><?php the_sub_field('subheading'); ?></h3>
<!-- count the heading elements -->
<?php $headings = count( get_sub_field( 'heading' ) ); ?>
<!-- Condition here if heading 1 echo H1 else echo H2 -->
<?php echo ($headings == 0) ? '<h1>' . the_sub_field('heading') . '</h1>' : '<h2>' . the_sub_field('heading') . '</h2>' ?>
<p><?php the_sub_field('description'); ?></p>
<!-- Your rest of code -->
出于SEO和可访问性的原因,您的HTML标记应考虑Heading tags ..的“语义”,因此请勿在H1标记之前使用H3标记。