自定义字段-显示缩略图(并自动调整大小)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义字段-显示缩略图(并自动调整大小)相关的知识,希望对你有一定的参考价值。

Whilst there are a number of ways of displaying thumbnails, this is still my favourite (even if it does require the most work!). First, upload timthumb to /wp-content/themes/yourtheme/ and create an image 250px by 250px with your site’s logo and upload it to yourtheme/images/. This is the image that will be displayed if no custom field is displayed. Then, for every thumbnail, you’ll need to create it in Photoshop and upload it to your blog. Next, create a custom field ‘Image’ with the path of the image as the value of the custom field. Now for the code:
  1. <?php $postimageurl = get_post_meta($post->ID, 'Image', true);
  2. if ($postimageurl) {
  3. ?>
  4. <img src="/wp-content/themes/NomeMag/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "Image", true); ?>
  5. &h=250&w=250&zc=1" alt="">
  6. <?php } else { ?>
  7. <img src="/wp-content/themes/NomeMag/images/wpshoutlogo.jpg" alt="WPShout.com | No image available" />
  8. (don't have a line break, just so it's readable)
  9. <?php } ?>

以上是关于自定义字段-显示缩略图(并自动调整大小)的主要内容,如果未能解决你的问题,请参考以下文章

无自定义字段的自动WORDPRESS缩略图

调整 Woocommerce 购物车缩略图的大小

addwidget显示滚动轴

将图像拉伸到浏览器边缘并根据浏览器的大小自动调整大小

thinkphp上传图片自动压缩问题

需要更改 [product_categories] Woocommerce 短代码缩略图大小