今天就给大家介绍两个函数,他们的功能类似,一个是include_once的集体引用,另一个是require_once的集体引用。
1、require_once
define('inlo_func', templatepath.'/inc'); // 定义集体 php 所在的文件夹 inc function inlo_requireall( $dir ){ // require_once 集体引用 php foreach( glob( "{$dir}/*.php" ) as $filename ) require_once $filename; } inlo_requireall( inlo_func ); // 执行函数
2、include_once
define('inlo_func', templatepath.'/inc'); // 定义集体 php 所在的文件夹 inc function inlo_includeall( $dir ){ // include_once 集体引用 php $dir = realpath( $dir ); if($dir){ $files = scandir( $dir ); sort( $files ); foreach( $files as $file ){ if( $file == '.' || $file == '..' ){ continue; }elseif( preg_match('/.php$/i', $file) ){ include_once $dir.'/'.$file; } } } } inlo_includeall( inlo_func ); // 执行函数
以上代码二选一加入 functions.php 里面即可,加入后,只要把需要引用的 php 文件放在 inc 文件夹里面效果就如同放在functions.php 里面一样了。
以上内容仅供参考!
推荐教程:php视频教程
以上就是php文件如何引用wordpress方法的详细内容。
