wordpress 缩略图_如何在WordPress中获取帖子缩略图URL

wordpress 缩略图

There are always a group of our readers who are trying to graduate the beginner level early and step into WordPress development. Many of them start by hacking their WordPress themes, creating child themes, or writing plugins. This makes them come across puzzling challenges. One such reader recently asked us how to get the post thumbnail URL in WordPress. The goal here is to just get the post thumbnail URL and then use it with their own markup. In this article, we will show you how to get the post thumbnail URL in WordPress.

总是有一群读者试图尽早毕业于初学者,并逐步进入WordPress开发。 他们中的许多人开始于破解他们的WordPress主题创建子主题编写插件 。 这使他们面临令人困惑的挑战。 一位这样的读者最近问我们如何在WordPress中获取帖子缩略图URL。 这里的目标是仅获取帖子缩略图 URL,然后将其与自己的标记一起使用。 在本文中,我们将向您展示如何在WordPress中获取帖子缩略图URL。

Note: You must know the basics of how WordPress themes work.

注意:您必须了解WordPress主题如何工作的基础知识。

Simply paste this code inside the loop code that you are writing.

只需将此代码粘贴到您正在编写的循环代码中即可。


<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
echo $thumb_url[0];
?>

Make sure to replace thumbnail-size to whatever image size you want to get. Default sizes are thumbnail, medium, large, and full. You can also use add and use additional image sizes. If you are using a custom image size then make sure to regenerate thumbnails. You can also set a default fallback image for post thumbnails.

确保将thumbnail-size替换为您想要的图像尺寸。 默认大小为缩略图,中,大和完整。 您还可以使用添加和使用其他图像尺寸 。 如果使用自定义图像尺寸,请确保重新生成缩略图 。 您还可以为帖子缩略图设置默认的后备图片

What this code does is that we first get the post thumbnail ID. Then we use that id to get the image path or URL using wp_get_attachment_image_src function, which returns an array that you can use with your own code.

该代码的作用是我们首先获取帖子的缩略图ID。 然后,我们使用该ID通过wp_get_attachment_image_src函数获取图像路径或URL,该函数返回一个数组,您可以将其与自己的代码一起使用。

We hope this article helped you learn how to get post thumbnail URL in WordPress. For feedback and questions, please leave a comment below.

我们希望本文能帮助您学习如何在WordPress中获取帖子缩略图URL。 对于反馈和问题,请在下面发表评论。

翻译自: https://www.wpbeginner.com/wp-themes/how-to-get-the-post-thumbnail-url-in-wordpress/

wordpress 缩略图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WordPress,你可以通过添加特色视频缩略图来为你的文章或页面增添美观的效果。根据引用提供的教程,可以按照以下步骤来实现: 1. 首先,确保你已经安装并激活了"Featured Video Plus"插件。这个插件可以让你方便地添加特色视频缩略图。 2. 在编辑文章或页面的页面,向下滚动到"Featured Video"选项。这个选项位于编辑器下方的"文档"选项卡旁边。 3. 在"Featured Video"选项,*** 除此之外,如果你想要设置默认的后备图片,可以参考引用提到的最佳功能图片插件和教程。这些插件可以让你为没有特色视频的文章自动分配一个默认的后备图片。 希望这些信息对你有所帮助!如果你还有其他问题,请随时向我提问。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [wordpress 缩略图_如何在WordPress添加精选视频缩略图](https://blog.csdn.net/cumyupx7788305/article/details/108606727)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [wordpress 缩略图_如何为WordPress发布缩略图设置默认的备用图片](https://blog.csdn.net/cumohuo9136/article/details/108608811)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值