Q:

list attachment on wordpress

i have this code:
 <?php
                $valid_ext = array("pdf", "doc");
                $args = array(
                    'post_type' => 'attachment',
                    'post_mime_type' => 'application/pdf',
                    'numberposts' => 40,
                    'post_status' => null,
                    'post_parent' => null, // any parent
                    );
                $attachments = get_posts($args);
                if ($attachments) {
                    foreach ($attachments as $post) {
                $ext = getFileExt(wp_get_attachment_url($post_id, false));
                if(in_array($ext, $valid_ext)) {
                 ?>
                <li> 
                    <div class="entry-date">
                        <abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO')?>">
                <?php unset($previousday); printf( __( '%1$s &#8211; %2$s', 'sandbox' ), the_date( '', '', '', false ), get_the_time() )?>
                        </abbr>
                    </div> 
                    <div id="post-<?php the_ID()?>" class="<?php sandbox_post_class()?> " style="padding:0; margin:0;">
                        <p style="font-size:11px; text-transform:uppercase;">
                            <?php setup_postdata($post);the_attachment_link($post_id, true);?>
                        </p>
                    </div> 
                </li>
                <?php
                                }
                    }
                }
            ?>

it gives me as output a date and a link with the document name.
<li> 
<div class="entry-date">
    <abbr title="2011-06-15T17:30:29+0200" class="published">
            15 giugno 2011 &ndash; 17:30        
            </abbr>
</div> 
<div style="padding:0; margin:0;" class="hentry p11 attachment inherit author-daniela-santanch category-senza-categoria untagged y2011 m06 d15 h17 " id="post-2158">
    <p style="font-size:11px; text-transform:uppercase;">
        <a title="la_stampa_07_06_2011" href="http://www.mpli.it/wp/wp-content/uploads/2011/06/la_stampa_07_06_2011.pdf">la_stampa_07_06_2011</a>                            </p>
</div> 

i'd like to get the post title linking directly to the document.
any help?

A:

Try this:
<?php
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null ); 
$attachments = get_posts( $args );
if ($attachments) {
    foreach ( $attachments as $post ) {
        setup_postdata($post);
        the_title();
        the_attachment_link($post->ID, false);
        the_excerpt();
    }
}
?>

