这是一个与wordpress相关的问题。我想转动通过前端提交表单提交的图像,您可以将外部网址提供给链接到其自己的源的图像。对于前者http://i.imgur.com/7qmFBPa.jpg将是点击图片链接的最终结果。下面是php看起来的样子:
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class = 'span4 reddit-image-single pull-left'>
<img src = "<?php echo $image[0]; ?>" width = "700px" class="img-rounded">
</div>
<?php }else{ ?>
<div class = 'span4 reddit-image-single pull-left'>
<img src = "<?php echo get_post_meta( $post->ID, 'wpedditimage', true ); ?>" width = "700px" class="img-rounded">
</div>
<?php } ?>
我如何修改上述代码?我对PHP很新。
答案 0 :(得分:0)
将图片包装在标签中,其中url为href
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class = 'span4 reddit-image-single pull-left'>
<a href="<?php echo $image[0];?>"><img src = "<?php echo $image[0]; ?>" width = "700px" class="img-rounded"></a>
</div>
<?php }else{ ?>
<div class = 'span4 reddit-image-single pull-left'>
<a href="<?php echo get_post_meta( $post->ID, 'wpedditimage', true ); ?>"><img src = "<?php echo get_post_meta( $post->ID, 'wpedditimage', true ); ?>" width = "700px" class="img-rounded"></a>
</div>
<?php } ?>
这是你要看的主线
<a href="<?php echo $image[0];?>"><img src = "<?php echo $image[0]; ?>" width = "700px" class="img-rounded"></a>