• Resolved kartlink

    (@kartlink)


    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);
        }
    }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • <?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) { ?>
        <h3>Attached files</h3>
        <?php
        foreach ($attachments as $attachment) {
            the_attachment_link($attachment->ID, false);
        }
    }
    ?>

    Is that what you mean?

    Thread Starter kartlink

    (@kartlink)

    Thanks very much, that works great

    ?? All’s good then.. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying (or not) a title for a list of attachments’ is closed to new replies.