Attachment image single page

时间:2012-11-21 作者:JonnyPlow

如何为下面的单个附件图像创建单个贴子页面并链接到它?

<?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(); ?>

1 个回复
最合适的回答,由SO网友:Chip Bennett 整理而成

提到the Template Hierarchy for attachment post types:

$mimetype。php$attachment.php

  • single-attachment.php
  • single.php
  • index.php
  • 因此,对于图像附件,请将模板文件命名为image.php.

    然后,要链接到附件的单个帖子视图,您可以像其他帖子一样链接到它:get_the_permalink( $postid ).

    结束

    相关推荐

    我可以使用PRE_GET_POSTS函数通过元键排除POST吗?

    我看到很多人更喜欢使用pre_get_posts 钩子代替query_posts. 下面的代码可以工作并显示所有具有元键“特色”的帖子function show_featured_posts ( $query ) { if ( $query->is_main_query() ) { $query->set( \'meta_key\', \'featured\' ); $query->set( \'meta_value\', \'