使用Wordpress并希望在此代码中使用PHP函数
<?php if ( is_page(19074) ) {
include("/home/something/public_html/wp-content/themes/mytheme/folder/page1.html");
}
elseif ( is_page(18956) ) {
include("home/something/public_html/wp-content/themes/mytheme/folder/page2.html");
}
elseif ( is_page(19082) ) {
include("home/something/public_html/wp-content/themes/mytheme/folder/page3.html");
}
else {
include("home/something/public_html/wp-content/themes/mytheme/folder/page4.html"); }?>
我不想在这里使用Wordpress PHP函数get_template_directory()就像我会这样做
<?php get_template_directory(); ?>/folder/page1.html
一直在尝试一些不同的解决方案,但PHP不是我最强的区域,所以一点帮助就太棒了。
答案 0 :(得分:1)
include(get_template_directory() . "/folder/page1.html");
OR
最好将它存储在变量中,以免造成很多次调用函数的开销。
$temp_dir = get_template_directory() ;
include($temp_dir . "/folder/page1.html");
include($temp_dir . "/folder/page2.html");
include($temp_dir . "/folder/page3.html");
include($temp_dir . "/folder/page4.html");
希望它有所帮助。