$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin development - Get thumbnails with array sizes parameter|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - Get thumbnails with array sizes parameter

matteradmin8PV0评论

I am trying to get both full and thumbnail images from post with wp_get_attachment_image_url:

wp_get_attachment_image_url( get_the_ID(), array('thumbnail, full'));

I know that by default size is thumbnail and I read from documentation that I can pass and array of sizes, but with above example, I am getting an error:

A non-numeric value encountered

The documentation is not clear about how to pass an array of sizes as parameter.

I am trying to get both full and thumbnail images from post with wp_get_attachment_image_url:

wp_get_attachment_image_url( get_the_ID(), array('thumbnail, full'));

I know that by default size is thumbnail and I read from documentation that I can pass and array of sizes, but with above example, I am getting an error:

A non-numeric value encountered

The documentation is not clear about how to pass an array of sizes as parameter.

Share Improve this question asked Jan 13, 2019 at 23:16 gdfgdfggdfgdfg 1721 silver badge15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You’re almost correct.

You really can pass an array as size parameter for that function, but...

$size (string|array) (Optional) Image size to retrieve. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default value: 'thumbnail'

So you can’t use it in the way you wanted to...

You have to pass name of the size or an array that will define the size in pixels (width and height).

You can get only one size with one call of that function (as it returns only one value - url of image in given size).

But that’s not a problem, just call it twice:

$thumb_url = wp_get_attachment_image_url( get_the_ID(), 'thumbnail');
$full_url = wp_get_attachment_image_url( get_the_ID(), 'full');
Post a comment

comment list (0)

  1. No comments so far