This question already has an answer here:
When I use the code below with two if
statements inside foreach
I get error Parse error: syntax error, unexpected 'endif' (T_ENDIF) in
:
<?php
$dataArray= [8242, 8084];
?>
<?php foreach($dataArrayas $dataId):
// A
$fieldA = get_field_object('field_a', $dataId);
$fileA = get_field( "file_a", $dataId);
// B
$fieldB = get_field_object('field_b', $dataId);
$fileB = get_field( "file_b", $dataId);
// Name
$name = get_field( "name", $dataId);
<div class="php-text-center">
<div class="name"><b><?php echo $name; ?></b></div>
if( $fileA ): ?>
<a href="<?php echo $fileA['url']; ?>">
<span class="data-icon-list-icon">
<i aria-hidden="true" class="php-icon fas fa-file-download"></i>
</span>
<span id="php-text" class="data-icon-list-text"><?php echo $fieldA['label']; ?></span>
</a>
<?php endif; ?>
if( $fileB ): ?>
<a href="<?php echo $fileB['url']; ?>">
<span class="data-icon-list-icon">
<i aria-hidden="true" class="php-icon fas fa-file-download"></i>
</span>
<span id="php-text" class="data-icon-list-text"><?php echo $fieldB['label']; ?></span>
</a>
<?php endif; ?>
</div>
<?php endforeach; ?>
What am I doing wrong? It works if I only use first if
. Best Regards
Aucun commentaire:
Enregistrer un commentaire