我使用reactjs构建了wodpress主题。我将graphql用于wordpress api以获取数据。但是问题是我无法将reactjs文件与wordpress主题文件排队。
要做同样的事情,我在Google上发现了类似的东西,但它不起作用
boolarr = [True, True, False, False, True, True]
atleastonetrue = bool(sum(boolarr))
是正确的还是有其他方法或者是否缺少某些内容。 我真的需要知道这一点。
答案 0 :(得分:2)
PHP提供了一个可以为您提供文件列表和目录的功能。通过使用glob,您可以列出目录中的每个.js文件,然后通过循环使其排入队列。
function enqueue_my_scripts(){
foreach( glob( get_template_directory(). '/path/*.js' ) as $file )
{
// $file contains the name and extension of the file
wp_enqueue_script( $file,get_template_directory_uri().'/path/'.$file);
}
}
add_action('wp_enqueue_scripts', 'enqueue_my_scripts');
另一方面不是glob使用相对路径,而wp_enqueue_script使用URL。这就是为什么我使用不同的功能来获取文件夹的路径和URI的原因。