如何在WordPress中将变量传递给模板部分?

我正在尝试调用模板部件, 但是每次调用它时我都想更改一个小细节。

现在我正在使用:

<?php get_template_part( 'ad-banner' ); ?>

我认为一定有类似的东西

<?php get_template_part( 'ad-banner', $variable='variable value' ); ?>

有人有建议吗?


#1


如果你使用locate_template()而不是get_template_part(), 则可以使用该php文件中的所有变量。

$variable='variable value';
include(locate_template('ad-banner.php'));

现在, 你可以在ad-banner.php中使用$ variable

参考

来源:

https://www.srcmini02.com/65212.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37321.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?