List Post Attachments – Remove Image Thumbnails

I’m using the following code to display a list of the posts attachments within a sidebar:

<ul>            
<?php $args = array(
'post_type' => 'attachment',
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
        echo '<p>This article has the following attachments:</p>';
        foreach ($attachments as $attachment) {
        echo '<li class="document">';
        the_attachment_link($attachment->ID, false);
        echo '</li>';}
        } else { 
        echo '<li class="nodocument">No documents attached to this article.</li>';
} ?>
</ul>

Most posts contain PDF’s, Zip files and JPG/PNG files. The code above does list the attachments, however, when the attachment is an image it displays a thumbnail rather than just a link to the image.

Read More

Can anyone advise how I can go about making sure each attachment is listed as a link?

Thanks,
Darren

Related posts

Leave a Reply

1 comment

  1. Instead of the_attachment_link use the following:

    echo wp_get_attachment_link($attachment->ID, 'full', false, false, true);
    

    wp_get_attachment_link is what’s being called internally by the_attachment_link, the last parameter set to true makes it output a text link instead of an image.