我正在使用高级自定义字段制作3个服务盒。
我想使用repeater字段循环三个div,其中包含六个段落和图像。存在的问题是,循环方式是正确的,但类名服务中的内容是单独循环的
我希望这些段落和图像在3个div中显示为两个。
<div class\'\'services>
<div class="box-service">Content Go Here</div>
<div class="box-service">Content Go Here</div>
</div>
<div class\'\'services>
<div class="box-service">Content Go Here</div>
<div class="box-service">Content Go Here</div>
</div>
<div class\'\'services>
<div class="box-service">Content Go Here</div>
<div class="box-service">Content Go Here</div>
</div>
Wordpress代码
<section class="services cf">
<div class="wrapper">
<?php if( have_rows(\'services_sections\') ): ?>
<?php while( have_rows(\'services_sections\') ): the_row();
// vars
$image = get_sub_field(\'services_icon\');
$title = get_sub_field(\'service_title\');
$description = get_sub_field(\'services_description\');
?>
<div class="service">
<div class="box-service">
<div class="pull-left">
<img src="<?php echo $image[\'url\']; ?>" alt="<?php echo $image[\'alt\'] ?>" />
</div>
<div class="line"></div>
<div class="right-word">
<h3><?php echo $title; ?></h3>
<p><?php echo $description; ?></p>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</section>
// -------- Services Styles --------- //
.services {
clear: both;
.line {
border: 1px solid #ebebeb;
}
.service {
background-color: $offwhitecolor;
width: 31%;
float: left;
margin: -5rem 1% 1%;
text-align: left;
position: relative;
-webkit-box-shadow: 0px 8px 18px rgba(38,40,44,0.2);
-moz-box-shadow: 0px 8px 18px rgba(38,40,44,0.2);
box-shadow: 0px 8px 18px rgba(38,40,44,0.2);
.box-service {
padding: 1rem 7.5% 1rem;
h3 {
font-family: \'Open Sans\', sans-serif;
font-size: 1.0rem;
font-weight: 700;
}
p {
font-family: \'Lato\', sans-serif;
font-size: 1.0037500100376rem;
font-weight: 300;
}
.right-word {
padding-left: 30px;
}
.left-icon {
margin: 35px -5px;
}
}
}
}
最合适的回答,由SO网友:Muhammad Riyaz 整理而成
您应该创建sub repeater field(让我们调用box_service
) 内部repeater field services_sections
. 然后创建子字段(services_icon, service_title, services_description
)在…内box_service
中继器字段。(请检查附件))
然后使用以下代码:
<section class="services cf">
<div class="wrapper">
<?php if( have_rows(\'services_sections\') ):
while( have_rows(\'services_sections\') ): the_row(); ?>
<div class="service">
<?php if( have_rows(\'box_service\') ):
while( have_rows(\'box_service\') ): the_row();
// vars
$image = get_sub_field(\'services_icon\');
$title = get_sub_field(\'service_title\');
$description = get_sub_field(\'services_description\');
?>
<div class="box-service">
<div class="pull-left">
<img src="<?php echo $image[\'url\']; ?>" alt="<?php echo $image[\'alt\'] ?>" />
</div>
<div class="line"></div>
<div class="right-word">
<h3><?php echo $title; ?></h3>
<p><?php echo $description; ?></p>
</div>
</div>
<?php endwhile; endif; ?>
</div>
<?php endwhile; endif; ?>
</div>