我有一个填充从ACF提取的数据的表。如果有可用的报告,它基本上会添加PDF格式的报告。我想我已经解决了这一部分,但我的代码非常复杂,我想用switch语句或类似的东西来简化它。此外,当没有可用的PDF文件时,如何使表格显示值“x”?它目前正在删除手机,我不希望它这样做。提前谢谢。
<table class="float-left table">
<thead>
<tr>
<th scope="col">Company</th>
<th scope="col">Annual Report</th>
<th scope="col">Interim Statement</th>
<th scope="col">Prospectus</th>
</tr>
</thead>
<tbody>
<?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
<?php if( have_rows( \'recent_documents\') ): ?>
<tr>
<th>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</th>
<?php while( have_rows( \'recent_documents\') ): the_row(); ?>
<?php if ( have_rows( \'new_document\') ): ?>
<?php while ( have_rows( \'new_document\') ): the_row(); ?>
<?php if (strpos(get_sub_field( \'report_type\'), "Annual") !==false): ?>
<td><a href="<?php the_sub_field(\'file\'); ?>" target="_blank"><i class="fas fa-file-pdf"></i>annual</a>
</td>
<?php endif; ?>
<?php if (strpos(get_sub_field( \'report_type\'), "Interim") !==false): ?>
<td><a href="<?php the_sub_field(\'file\'); ?>" target="_blank"><i class="fas fa-file-pdf"></i>interim</a>
</td>
<?php endif; ?>
<?php if (strpos(get_sub_field( \'report_type\'), "Prospectus") !==false): ?>
<td><a href="<?php the_sub_field(\'file\'); ?>" target="_blank"><i class="fas fa-file-pdf"></i>Prospectus</a>
</td>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; ?>
</tr>
<?php endif; ?>
<?php endwhile; endif; wp_reset_postdata(); ?>
</tbody>
</table>