您可以不使用wp_enqueue_script
(加载一个JS文件,您将无法使用PHP),而只需在wp_head
或wp_footer
挂钩。。。。或者您可以使用wp_localize_script()
wp_enqueue_script( \'some_handle\' );
$instance = // not sure how you are fetching this value
$array = array( \'thumbs\' => $instance["hasThumbs"],
\'history\' => $instance["historyEnabled"],
\'time\' => $instance["transitionTime"] * 1000,
\'autoplay\' => $instance["autoplayEnabled"]),
\'loop\' => $instance["isLooped"]),
\'counter\' => $instance["hasCounter"]),
\'zoomable\' => $instance["zoomable"]),
\'hideFlash\' => $instance["hideFlash"] );
wp_localize_script( \'some_handle\', \'object_name\', $array );
然后修改JS文件,从名为“object\\u name”的JS对象中提取值,其中对象的属性对应于“wp\\u localize\\u script”中的数组键
(function ($) {
"use strict";
$(function () {
var $gallery = $("#gallery").photogallery(
"a",
{
thumbs: object_name.hasThumbs,
history: object_name.history,
time: object_name.time,
autoplay: object_name.autoplay,
loop: object_name.loop,
counter: object_name.counter,
zoomable: object_name.zoomable,
hideFlash: object_name.hideFlash
}
);
});
}(jQuery));