Created
September 6, 2012 07:50
-
-
Save ms-studio/3652711 to your computer and use it in GitHub Desktop.
WordPress attachment toolbox function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function attachment_toolbox() { | |
global $post; | |
if($attachments = get_children(array( | |
'post_parent' => get_the_ID(), | |
'post_type' => 'attachment', | |
'numberposts' => -1, // -1 = show all | |
'post_status' => null, | |
'post_mime_type' => 'application', | |
// 'post_mime_type' => 'application/msword,application/pdf', | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
))) { | |
?><div class="fichiers-joints"> | |
<h4 class="unstyled"><span class="rel-title">Fichiers joints:</span></h4> | |
<ul class="attach-list clean zero"> | |
<?php | |
foreach($attachments as $attachment) { | |
$attimg = wp_get_attachment_image($attachment->ID,$size); | |
$atturl = wp_get_attachment_url($attachment->ID); | |
$attlink = get_attachment_link($attachment->ID); | |
$postlink = get_permalink($attachment->post_parent); | |
$atttitle = apply_filters('the_title',$attachment->post_title); | |
$description = $attachment->post_content; | |
$filesize = filesize( get_attached_file( $attachment->ID ) ); | |
$filesize = size_format($filesize); | |
$filetype = get_post_mime_type($attachment->ID); | |
echo '<li class="attch-li"><a href="'.$atturl.'" class="attach-link" title="Télécharger le document">'.$atttitle.'</a> ('; | |
if ( $filetype == 'application/pdf' ) { | |
echo '<span class="small">PDF</span>, '; | |
} elseif ( $filetype == 'application/msword' ) { | |
echo '<span class="small">DOC</span>, '; | |
} | |
echo '<span class="small">' . $filesize . '</span>)</li>'; | |
} // end foreach | |
?></ul></div> | |
<?php | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment