如何检测 ACF 行内容类型

How to detect an ACF row content type

我正在尝试在 wordpress 网站上使用 fancybox 构建一个画廊。这些图库项目是高级自定义字段 (ACFS) 中继器。

问题是,客户只希望某些图库项目是 links,因为有些只是带有文本的彩色框,因此不应是 link 并且不应打开在花式盒子里。

正如您在下面的代码中看到的,我调用了中继器中的所有行,并将它们放置在自己的 div 中,并带有 href。

如何检测该行是图像还是文本框,并相应地添加 href?

<?php
if( have_rows('p3projectsres') ):
    while ( have_rows('p3projectsres') ) : the_row(); ?>
         <div class="s3block">
        <p> <a href="<?php the_sub_field('p3projectreshires'); ?>" rel="lightbox" title="<?php the_sub_field('p3projectresdescription'); ?>">

                <!-- <div class="locationscript"><?php the_sub_field('p3projectreslocation'); ?></div> -->
                <div class="s3blockblurb">
                    <div class="scribe7">   
                        <?php the_sub_field('p3projectresblurb'); ?>
                    </div>

                    <div class="s3blockfaded"><?php the_sub_field('p3projectreslocation'); ?></div>

                </div>
                <img src="<?php the_sub_field('p3projectrespreview'); ?>" /> 
            </a></p>
        </div>
    <?php  endwhile;
else : endif;
?>

看这里的问题,在"our work"下:www.entirecreative.com/stone

您可以使用 get_sub_field() 检索字段的值(与使用 the_sub_field() 回显相反)。如果未设置该值,它将 return false,因此可以在 if 语句中使用它来仅输出 A open/close 标签"p3projectreshires" 子字段设置在转发器行上。您还可以通过选中 "p3projectreshires".

有条件地包含预览图像
<?php
if( have_rows('p3projectsres') ):
    while ( have_rows('p3projectsres') ) : the_row(); ?>
         <div class="s3block"><p> 
         <!-- 
             check to see if there is a value for "p3projectreshires" 
             and if there is open the A tag
         -->
         <?php if ( get_sub_field('p3projectreshires') ) : ?>
             <a href="<?php the_sub_field('p3projectreshires'); ?>" rel="lightbox" title="<?php the_sub_field('p3projectresdescription'); ?>">
         <?php endif; ?>

                <div class="s3blockblurb">
                    <div class="scribe7">   
                        <?php the_sub_field('p3projectresblurb'); ?>
                    </div>

                    <div class="s3blockfaded"><?php the_sub_field('p3projectreslocation'); ?></div>

                </div>
                <!-- Only include the preview image if it is set -->
                <?php if ( get_sub_field('p3projectrespreview') ) : ?>
                     <img src="<?php the_sub_field('p3projectrespreview'); ?>" /> 
                <?php endif; ?>
         <!-- 
             check to see if there is a value for "p3projectreshires" 
             and if there is close the A tag
         -->
         <?php if ( get_sub_field('p3projectreshires') ) : ?>
            </a>
        <?php endif; ?>
        </p></div>
    <?php  endwhile;
else : endif;
?>