1
votes

Im stuck.

The code below works fine for the most part, except, I want the <h4>Attachments</h4> appear only if there are attachments. Right now it appears whether there are attachments or not. If I move <h4>Attachments</h4> after while have-rows repeater, it appears with each attached document. This is driving me insane.

<?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; ?>

Any ideas how to resolve this issue

1

1 Answers

0
votes

you can do something like this.

show this code be carefully and please do your self.

<?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; ?>

Or

you can use this too.

$image = get_sub_field('image');
$filesize = filesize( get_attached_file( $image ) );

if($filesize){
echo "attachment is available";
}
else{
echo "not";
}

filesize() :- Returns the size of the file in bytes, or FALSE (and generates an error of level E_WARNING) in case of an error.

i hope this helps for you thanks.