Attachment Templates

Posted on Thursday, December 4th, 2008 at 1:30 pm in

If you want different layouts for different attachment file pages, you can include specific attachment templates within a theme based on the first part of the attachment MIME type.

Examples might include:

  • image.php
  • video.php
  • audio.php
  • application.php

Example:image.php


<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div class="post">
<h2><?php the_title(); ?></h2>

<div class="attachment">
<a href="<?php echo wp_get_attachment_url($post->ID); ?>"><?php echo wp_get_attachment_image( $post->ID, 'medium' ); ?></a>
<?php the_content(); ?>
<p><small>Posted under <a href="<?php echo get_permalink($post->post_parent); ?>" rev="attachment"><?php echo get_the_title($post->post_parent); ?></a></small></p>
</div>

<?php endwhile; endif; ?>
</div>
You might also be interested in

WordPress Theme Development

Top