Wordpress基于模板部分的不同图像大小

问题描述 投票:0回答:1

我主题中的文件夹结构如下所示:

  • 可湿性粉剂内容/主题/主题/ 谐音/ 内容hero.php

我正在使用get_template_part('partials/content, 'hero')来包含模板部分。

我在wp_calculate_image_sizes中使用functions.php过滤器为我的图像添加自定义尺寸属性。我需要根据调用wp_get_attachment_image函数的模板部分来改变大小,但我不确定如何?

php wordpress responsive-images
1个回答
0
投票

将get_template_part之前的大小调用为变量,如:

$thesize = "here go the size you need";
set_query_var( 'variable_size', $thesize );
get_template_part('partials/content, 'hero'); 

所以现在在content-hero.php里面你可以得到你需要的变量$ variable_size。

希望这对你有用!

© www.soinside.com 2019 - 2024. All rights reserved.