您需要the_sub_field('owl_carousel')使用 Wordpress 在没有插件的情况下从字段中删除滑块。
我正在使用这段代码:
<?php $i = 0; ?>
<?php while( have_rows('project_sections') ): the_row(); ?>
<section class="<?php if ($i % 2 == 0) : ?>bg-gray<?php else: ?>bg-white<?php endif; ?>">
<div class="container">
<h2 class="page-head_sub-title"><?php the_sub_field('project_sections_title'); ?></h2>
<?php the_sub_field('project_sections_description'); ?>
<?php //var_dump(get_sub_field('owl_carousel')); ?>
</div>
<?php
$args = array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'orderby' => 'menu_order',
'order' => 'ASC',
'numberposts' => 1, // number of images (slides)
'post_mime_type' => 'image'
);
if ( $images = get_children( $args ) ) {
// if there are no images in post, don't display anything
echo '<div class="owl-carousel-wrap project-gallery ">
<div id="projectGalleryProject" class="owl-carousel owl-loaded owl-drag">
<a href="#projectPhotosProject" data-slide-to="0">
';
foreach( $images as $image ) {
echo '<div class="item" data-toggle="modal" data-target="#projectGalleryProjectModal"><div class="project-gallery_item">' . wp_get_attachment_image( $image->ID, 'project_slider' ) . '</div></div>';
}
echo '</a></div></div>';
}
?>
<div class="js-control-project-gallery-project">
<div class="carousel-control-prev" aria-hidden="true"><span class="icon-arrow"></span></div>
<div class="carousel-control-next" aria-hidden="true"><span class="icon-arrow"></span></div>
</div>
</section>
<?php $i++; ?>
<?php endwhile; ?>
<?php endif; ?>
显示所有上传的图像,直接添加到滑块字段的图像除外。您需要以某种方式访问该字段'owl_carousel',并且您可能需要检查字段中每个部分的值是否存在if exist。那些。如果图像加载到滑块中,则显示滑块。
如何更改现有代码以正确显示滑块?
应该去外地
get_sub_field('owl_carousel')