duanjiao2978 2013-07-18 22:52
浏览 79
已采纳

Wordpress - 将自定义缩略图链接到完整大小的附件图像

I'm coding a custom theme and I want to link a custom sized thumbnail image to the full size (or large) version of the image.

The code I'm using is:

<?php 
$attachment_id = get_field('main_product_photo');
$size = "main-product-thumb"; // (thumbnail, medium, large, full or custom size)
wp_get_attachment_image( $attachment_id, $size ); 
$image = wp_get_attachment_image_src( $attachment_id, $size );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<a href="<?php echo $image[0]; ?>"><img src="<?php echo $image[0]; ?>"></a>

However, this just links to my thumbnail sized image. Does anyone have a quick fix for this? Thanks!

  • 写回答

1条回答 默认 最新

  • duannuci4008 2013-07-18 23:27
    关注
    <?php 
    $attachment_id = get_field('main_product_photo');
    $size = "main-product-thumb"; // (thumbnail, medium, large, full or custom size)
    wp_get_attachment_image( $attachment_id, $size ); 
    $image = wp_get_attachment_image_src( $attachment_id, $size );
    $post_thumbnail_url = wp_get_attachment_url( $attachment_id  );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    ?>
    <a href="<?php echo $post_thumbnail_url; ?>"><img src="<?php echo $image[0]; ?>"></a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号