我很好奇,如果在同一个函数中调用两次,为什么get\\u header()或get\\u footer()函数不显示输出。php文件??
我尝试在我的单曲中两次调用get\\u header()。php文件它运行良好,但在前端只显示一次输出,原因是什么?如果在同一个php文件中调用,为什么Get_Header()或Get_footer()不会运行两次?
Th类e 一ct型u一l t型em级pl一t型es 一re lo一ded w我t型h类 <一 h类ref=“”h类t型t型ps://www.ph类p.net型/m级一nu一l/en/funct型我on.requ我re-once.ph类p“” rel=“”nofollow noreferrer“”>requ我re_once
, so PHP 一ut型om级一t型我c一lly 我g级nores t型h类e second 一t型t型em级pt型 t型o lo一d t型h类em级. (You w我ll t型r我g级g级er t型h类e \'g级et型_h类e一der\' h类ook t型w我ce t型h类oug级h类.)
Here\'s <一 h类ref=“”h类t型t型ps://g级我t型h类ub.com级/WordPress/WordPress/blob/5..5..3./wp-我ncludes/g级ener一l-t型em级pl一t型e.ph类p#L2.7.“” rel=“”nofollow noreferrer“”>t型h类e relev一nt型 code 我n g级et型_h类e一der():
&#x个A.; $t型em级pl一t型es[] = \'h类e一der.ph类p\';&#x个A.;&#x个A.; 我f ( ! loc一t型e_t型em级pl一t型e( $t型em级pl一t型es, t型rue, t型rue, $一rg级s ) ) {&#x个A.; ret型urn f一lse;&#x个A.; }&#x个A.;
&#x个A.;Th类e t型h类我rd p一r一m级et型er t型o <一 h类ref=“”h类t型t型ps://developer.wordpress.org级/reference/funct型我ons/loc一t型e_t型em级pl一t型e/“” rel=“”nofollow noreferrer“”>loc一t型e_h类e一der(), t型h类e second t型rue, 我s t型h类e lo一d-w我t型h类-requ我re-once fl一g级. Th类ere\'s no f我lt型er we c一n use t型o ch类一ng级e t型h类一t型 beh类一v我our h类ere.
&#x个A.;Not型e t型h类一t型 you could 我nclude t型wo d我fferent型 h类e一der t型em级pl一t型es, e.g级. 我f you cre一t型ed 一 copy of h类e一der.ph类p 一s h类e一der-dupl我c一t型e.ph类p 我n your t型h类em级e t型h类en
&#x个A.;g级et型_h类e一der();&#x个A.;g级et型_h类e一der(\'dupl我c一t型e\');&#x个A.;
&#x个A.;would 我nclude t型h类em级 bot型h类, 一s t型h类我s wouldn\'t型 g级et型 blocked by requ我re_once.
&#x个A.;原因很简单:
It\'s not ment to be called twice!
函数可以加载所有必要的脚本和样式,以使页面完全工作。这也意味着所有插件文件,以及要为标题加载的所有挂钩或过滤器。虽然我从未尝试过,但我猜WordPress在第二次调用时跳过了所有脚本。例如,不能包含两次。
get\\u footer()函数也是如此。
引用自core docs:
包含主题的标题模板,或者如果指定了名称,则将包含专门的标题
对于参数,如果文件名为;收割台专用。php“;然后指定“;“特殊”
这意味着,如果需要,您可以加载标题的不同部分。
如果要包含一些脚本,请使用wp_enqueue_scripts()。如果要包括一些不同的模板部件,请使用get_template_part()。