wordpress函数文件,如何循环一次?
我试图循环遍历wordpress functions.php文件中的一些require_once语句,如下所示wordpress函数文件,如何循环一次?,wordpress,loops,foreach,include,require-once,Wordpress,Loops,Foreach,Include,Require Once,我试图循环遍历wordpress functions.php文件中的一些require_once语句,如下所示 // Initial theme setup require_once locate_template('/inc/init.php'); // Register widget areas require_once locate_template('/inc/sidebar.php'); ... 为什么下面的循环不起作用 $theme_includes = array( '/
// Initial theme setup
require_once locate_template('/inc/init.php');
// Register widget areas
require_once locate_template('/inc/sidebar.php');
...
为什么下面的循环不起作用
$theme_includes = array(
'/inc/init.php', // Initial theme setup
'/inc/sidebar.php', // Register widget areas
'/inc/scripts.php', // Register scripts and stylesheets
'/inc/nav.php', // Main navigation
'/inc/cleanup.php', // Cleanup
'/inc/customizer.php',
'/inc/template-tags.php', // Custom template tags
'/inc/extras.php', // No theme functions
'/inc/analytics.php' // Google Analytics
);
foreach ( $theme_includes as $include ) {
require_once locate_template( $include );
}
我没有收到任何错误消息,但文件未加载如果您检查,您将发现该函数包含3个参数:
locate_template( $template_names, $load, $require_once )
$template\u name
:应该是要搜索的文件/模板数组
为了$load
:布尔值,如果设置为true,将在找到文件时加载文件$require\u once
:布尔值,如果设置为true,将使用require\u once php函数加载文件$theme_includes = array(
'/inc/init.php', // Initial theme setup
'/inc/sidebar.php', // Register widget areas
'/inc/scripts.php', // Register scripts and stylesheets
'/inc/nav.php', // Main navigation
'/inc/cleanup.php', // Cleanup
'/inc/customizer.php',
'/inc/template-tags.php', // Custom template tags
'/inc/extras.php', // No theme functions
'/inc/analytics.php' // Google Analytics
);
locate_template( $theme_includes, true, true );
如果在相对路径之前添加$\u SERVER['DOCUMENT\u ROOT'],会发生什么情况?我找到了解决方案。。我使用的不是
locate\u template
,而是get\u template\u directory()
,但仍然不知道为什么第一个版本不起作用