I am trying to show a list of any Word/PDF/Excel/Zip attachments to my posts, but logically enough I don’t want the heading to show when there are none of those attachments on the post. Can anyone tell me where I can put that H3 within the code? Thanks in advance!
<h3>Attached files</h3>
<?php
// place inside loop
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'application/zip, application/msword, application/vnd.ms-excel, application/pdf',
'numberposts' => null,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
the_attachment_link($attachment->ID, false);
}
}
?>