markdown 如何获取所有WordPress特色图像大小及其URL

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 如何获取所有WordPress特色图像大小及其URL相关的知识,希望对你有一定的参考价值。

# [How to get all featured image sizes and their URLs?](https://wordpress.stackexchange.com/questions/206509/how-to-get-all-featured-image-sizes-and-their-urls)

Is there a standard way to get all the registered sizes of the featured images? One can register different sizes with add_image_size(). What I need, is to get all the sizes of a featured image of a post. Something like this:

`$sizes = get_post_feature_image_sizes($postid);`

...which will return an array of objects like this (here in JSON format):
```json
[
{width: 200, height: 300, url: 'http://.........../wp-content/uploads/2015/10/file-200x300.jpg'},
{width: 300, height: 400, url: 'http://.........../wp-content/uploads/2015/10/file.jpg'},
]
```
Is there anything like this, or I will have to scan all the upload folder file names with regex?


----------


#### I don't remember a function that will do precisely that, but it is easily achieved with API overall:

1.   Retrieve attachment ID with [get_post_thumbnail_id()](https://developer.wordpress.org/reference/functions/get_post_thumbnail_id/)
2.   Retrieve available sizes with [get_intermediate_image_sizes()](https://developer.wordpress.org/reference/functions/get_intermediate_image_sizes/)
3.   For each size use [wp_get_attachment_image_src()](https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/), which gives precisely data you need (URL and dimensions).

以上是关于markdown 如何获取所有WordPress特色图像大小及其URL的主要内容,如果未能解决你的问题,请参考以下文章

wordpress获取当前分类的ID

WordPress 安装 Markdown 插件

markdown 如何删除包含部分单词的WordPress评论?

markdown WordPress主题参考,如何,片段,存储库说明

如何在 wordpress/woocommerce 中获取所有订单详细信息? [复制]

WordPress:如何获取“the_content”过滤器的所有注册函数