| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: WP-Attachments |
| 4 |
Plugin URI: http://www.milesimarco.altervista.org/wp-attachments |
| 5 |
Description: Automatically shows your doc, xls and pdf attachments under every post and page. Simply and Easily. As it should be! |
| 6 |
Author: Marco Milesi |
| 7 |
Version: 2.0 |
| 8 |
Author URI: http://www.milesimarco.altervista.org/ |
| 9 |
*/ |
| 10 |
|
| 11 |
add_filter( 'the_content', 'wpatt_content_filter' ); |
| 12 |
function wpatt_content_filter( $content ) { |
| 13 |
global $post; |
| 14 |
|
| 15 |
$attachments = get_posts( array( |
| 16 |
'post_type' => 'attachment', |
| 17 |
'post_mime_type' => 'application/pdf,application/msword,application/msexcel', |
| 18 |
'posts_per_page' => 100, |
| 19 |
'post_parent' => $post->ID |
| 20 |
) ); |
| 21 |
|
| 22 |
if ( $attachments ) { |
| 23 |
$content .= '<h2>Attachments:</h2>'; |
| 24 |
$content .= '<ul class="post-attachments">'; |
| 25 |
foreach ( $attachments as $attachment ) { |
| 26 |
$class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type ); |
| 27 |
$title = wp_get_attachment_link( $attachment->ID, false ); |
| 28 |
$content .= '<li class="' . $class . '">' . $title . '</li>'; |
| 29 |
} |
| 30 |
$content .= '</ul>'; |
| 31 |
} |
| 32 |
|
| 33 |
return $content; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
?> |