Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I make a single post page for a single attachment image below and link to it?

<?php get_header(); ?>
<div id="body">
<?php if (have_posts()) : ?>
<div class="page_title">
<h2><?php single_cat_title(); ?></h2>
</div>
<div class="photos">
<ul class="lb-album">
<?php while (have_posts()) : the_post(); ?>
<?php $images = get_post_meta($post->ID, 'za_plupload');  ?>
<?php   
$images = implode( ',' , $images );
$images = $wpdb->get_col( "
SELECT ID FROM {$wpdb->posts}
WHERE post_type = 'attachment'
AND ID in ({$images})
ORDER BY menu_order ASC
" );
?>
<?php $i = 0; ?>
<?php foreach ($images as $att) {
$src = wp_get_attachment_image_src($att, 'full');
$src = $src[0]; 
$image_path =  thumbGen($src,330,0,"crop=1&halign=center&valign=center&return=1");
$image_all = get_bloginfo('url').$image_path;
$my_image = array_values(getimagesize($image_all));
list($width, $height, $type, $attr) = $my_image;
?>
<li class="box image_holder" style="height:<?php echo $height; ?>px!important;"><a href="<?php echo $image_path2; ?>" style="height:<?php echo $height; ?>px!important;"><img src="<?php echo $image_path; ?>" alt="" width="330"  height="<?php echo $height; ?>" class="image" /></a></li>
<?php $i++; ?>
<?php } ?>
<?php endwhile; ?>
<div class="clear"></div>
</ul>
</div>
<?php endif;?>
<?php wp_reset_query(); ?>
<div class="clear"></div>
</div>
<div class="clear"></div>
<?php get_footer(); ?>
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Refer to the Template Hierarchy for attachment post types:

  • `$mimetype.php
  • $attachment.php
  • single-attachment.php
  • single.php
  • index.php

So for an image attachment, name your template file image.php.

Then, to link to the single post view for an attachment, you would link to it like any other post: get_the_permalink( $postid ).

share|improve this answer
    
Thanks it put me in the right direction. –  JonnyPlow Nov 21 '12 at 23:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.