有人能给我解释一下这个函数在循环中是如何工作的吗?
我在wordpress循环中多次使用此函数,如下所示:
loop start
get_template_part("template/part", "example");
loop end
这方面的神奇之处在于,我可以调用如下函数the_title()
模板没有任何问题part-example.php
.但如果我尝试将自定义变量传递给part-example.php
这样,它就会失败:
$var = "variable";
Start loop
get_template_part("template/part", "example");
End loop
内部为exmaple。php文件echo $var; // this will fail
我确实通过阅读great找到了解决这个问题的方法this article, 它正在使用include( locate_template() )
. 但我只是想知道,post数据是如何通过get_template_part()
?
提前谢谢。