我有一个WordPress博客。在单个博客文章中,作者可以上传pdf文件。然后,在存档页面的一个表格中,我希望最终用户可以下载附件,而不必转到单个帖子页面。
存档页面:
<table class="table archives-table">
<thead>
<tr>
<th scope="col" width="100">IMG</th>
<th scope="col">Title</th>
<th scope="col" width="250">Date</th>
<th scope="col" width="100">PDF</th>
</tr>
</thead>
<tbody>
<?php if ( have_posts() ) : ?>
<?php while(have_posts()) : the_post(); ?>
<tr>
<th scope="row">
<?php if(has_post_thumbnail()) : ?>
<?php the_post_thumbnail('thumbnail', array(
'class' => 'rounded',
)); ?>
<?php else : ?>
<img src="http://local.mysite.com/wp-content/uploads/2019/11/no-image.png" class="rounded">
<?php endif; ?>
</th>
<td>
<a class="news-title" href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</td>
<td>
<?php the_date(); ?>
</td>
<td>
<?php $attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => 'image'
));
if ( $attachments ) { ?>
<a href="<?php echo wp_get_attachment_link(); ?>"><img src="http://local.mysite.com/wp-content/uploads/2019/11/pdf-file-icon-blue.png" alt="PDF Download"></a>
<?php }
else { ?>
<i class="material-icons">not_interested</i>
<?php } ?>
</td>
</tr>
<?php endwhile; ?>
<?php else : ?>
<tr>
<td>No Post</td>
</tr>
<?php endif; ?>
</tbody>
</table>