2017-12-27 826 views
0

在我的主题文件夹结构如下所示:WordPress的不同的图像大小

  • 的wp-content /主题/主题/
    • 谐音/
      • 内容英雄.PHP

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

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

回答

0

呼叫大小get_template_part之前到一个变量,如:所以现在内容hero.php内

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

,你将有可用的变量$ variable_size与你所需要的。

希望它适合你!

相关问题