【问题标题】:ACF Custom Post Fields - Conditional Repeater TitleACF 自定义帖子字段 - 条件重复标题
【发布时间】:2018-12-26 23:41:49
【问题描述】:

我卡住了。

下面的代码大部分都可以正常工作,除了我想要<h4>Attachments</h4> 仅在有附件时出现。现在看有没有附件。如果我在 while have-rows 转发器之后移动 <h4>Attachments</h4>,它会出现在每个附加文档中。这让我发疯。

<?php if( have_rows('attachment_repeater') ): ?>

    <h4>Attachments</h4>

        <?php while( have_rows('attachment_repeater') ): the_row();

        $case_document = get_sub_field('case_document');
        $title = $file['title'];
    ?>


<?php if( get_sub_field('case_document') ): ?>
<div style="border-bottom:1px solid #dfdfdf;padding:10px 0; width:100%; display:table">
<div><a href="<?php echo $case_document['url']; ?>"><?php echo $case_document['title']; ?></a></div>
</div>
<?php endif; ?> 


    <?php endwhile; ?>
<?php endif; ?>

关于如何解决此问题的任何想法

【问题讨论】:

    标签: php wordpress advanced-custom-fields


    【解决方案1】:

    你可以这样做。

    请谨慎显示此代码,请自行处理。

    <?php if( have_rows('repeater') ): ?>
    
        <ul class="slides">
    
        <?php while( have_rows('repeater') ): the_row(); 
    
            $image = get_sub_field('image');
    
           if($image){
            <h4>Attachments</h4>
           }
    
    
            ?>
    
            <li class="slide">
    
                <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
    
                <p class="caption"><?php the_sub_field('caption'); ?></p>
    
            </li>
    
        <?php endwhile; ?>
    
        </ul>
    
    <?php endif; ?>
    

    或者

    你也可以用这个。

    $image = get_sub_field('image');
    $filesize = filesize( get_attached_file( $image ) );
    
    if($filesize){
    echo "attachment is available";
    }
    else{
    echo "not";
    }
    

    filesize() :- 以字节为单位返回文件的大小,或 FALSE(和 发生错误时会生成 E_WARNING 级别的错误。

    我希望这对你有帮助 谢谢。

    【讨论】:

      猜你喜欢
      • 2019-06-12
      • 2021-11-30
      • 2017-05-10
      • 2013-11-23
      • 2021-01-09
      • 2018-06-30
      • 2019-06-27
      • 1970-01-01
      • 2021-05-17
      相关资源
      最近更新 更多