Permalink
Browse files

Attachment.php

Signed-off-by: Matthias Kampitsch <matthias@starflower.at>
  • Loading branch information...
1 parent 5241fee commit b70834e95ef9ef822385ce2e6ea7ea72de872a65 @starflower starflower committed Jun 17, 2011
Showing with 52 additions and 0 deletions.
  1. +47 −0 attachment.php
  2. +5 −0 style.css
View
@@ -0,0 +1,47 @@
+<?php get_header(); ?>
+
+ <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
+
+ <article <?php post_class() ?> id="post-<?php the_ID(); ?>">
+
+ <h2 class="sub-title">Attachment</h2>
+ <h1 class="entry-title"><?php the_title(); ?></h1>
+
+ <div class="entry-content entry">
+ <p>
+ <?php
+ function format_bytes($size) {
+ $units = array(' B', ' KB', ' MB', ' GB', ' TB');
+ for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
+ return round($size, 2).$units[$i];
+ }
+
+ $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_excerpt();
+ the_content();
+ echo "File type: ";
+ print_r($post->post_mime_type);
+ echo "<br/>File size: ";
+ print(format_bytes(filesize(get_attached_file($post->ID, true ))));
+ echo "<br/>";
+ echo wp_get_attachment_link( $post->ID, '' , false, false, 'Download' );
+
+ }
+ }
+ ?>
+
+ </p>
+ </div>
+
+ <?php edit_post_link('Edit this entry','','.'); ?>
+
+ </article>
+
+ <?php endwhile; endif; ?>
+
+
+<?php get_footer(); ?>
View
@@ -247,6 +247,11 @@ article {
font-size: 14px;
}
+.sub-title {
+ color: #ccc;
+ padding: 0 0 4px 0;
+}
+
.entry-content {}
.entry-content a {}
.entry-content a:hover {}

0 comments on commit b70834e

Please sign in to comment.