WordPress教程

WordPress调用缩略图/特色图像url的方法

阿里云

特色图像、缩略图是 WordPress 中一个不算复杂却十分难以理解的一个概念(至少我是这么认为的),特色图像的设置和调用是分两步来进行的,特色图像在 WordPress 中是属于日志缩略图的一种,即可以理解为默认缩略图的种类可分为 大、中、小和特色图像等缩略图,在后台默认的编辑器中,我们可以在文章中任意的调用大、中、小、等缩略图插入到文章,当然如果你愿意的话 WP 还可以插入原图。当主题的结构中支持将文章中的特色图像显示在文章概要或是文章索引中的时候,我们还可以在后台将喜欢的图像设置为特色图像。

可以用 the_post_thumbnail 函数 也可以用 get_the_post_thumbnail 函数,这样会直接输出带 img 的完整代码,有的时候并不是我们需要的,如果单纯的只需要图像的 URL,我们可以这样做。

也想出现在这里?联系我们
创客主机

调用缩略图的 URL:

  1. <a href="<?php the_post_thumbnail_url( 'full' ); ?>"><?php the_post_thumbnail(); ?></a>

如果不加链接:

  1. <?php if ( has_post_thumbnail() ) { ?>
  2. <?php the_post_thumbnail(); ?>
  3. <?php } else {?>
  4. <img src="这里填写默认图片地址"/>
  5. <?php } ?>

参数设置:

  1. the_post_thumbnail(); // 无参数,默认调用Thumbnail
  2. the_post_thumbnail('thumbnail'); // Thumbnail (默认尺寸 150px x 150px max)
  3. the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max)
  4. the_post_thumbnail('large'); // Large resolution (default 640px x 640px max)
  5. the_post_thumbnail('full'); // Full resolution (original size uploaded)
  6. the_post_thumbnail( array(100,100) ); // Other resolutions,自定义长宽

WordPress 调用缩略图/特色图像 url 的方法

已有 353 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!