使用 wordpress 时,您应该在主题 function.php 中包含所有 js 调用。如果你用谷歌搜索 wp_enqueue_script,你会发现很多资源。这是在 googles CDN 上使用 jquery 的一种方法:
function tm_javascript() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js', false, '1.4.2', true);
wp_enqueue_script('jquery');
// load a JS file from my theme: js/theme.js
wp_enqueue_script('tm_filter', get_bloginfo('template_url') . '/js/filterable.js', array('jquery'), false, true);
wp_enqueue_script('tm_hash', get_bloginfo('template_url') . '/js/jquery.ba-hashchange.min.js', array('jquery'), false, true);
wp_enqueue_script('tm_ui', get_bloginfo('template_url') . '/js/jquery-ui-widget.js', array('jquery'), false, true);
wp_enqueue_script('tm_scroll', get_bloginfo('template_url') . '/js/jquery.smoothDivScroll-1.1-min.js', array('jquery', 'tm_ui'), false, true);
wp_enqueue_script('tm_ajaxaks', get_bloginfo('template_url') . '/js/aks.js', array('jquery', 'tm_hash', 'tm_filter', 'tm_ui', 'tm_scroll'), false, true);
}
}
add_action('init', 'tm_javascript');
最开始的部分从 wordpress 中注销包含的 jquery,然后加载实际的 1.4.2 版本。您可以修改代码以始终加载最新版本等。jsut google it up。
然后,您可以从主题子文件夹 /js/ 加载特定于主题的 js 文件,真正有用的部分是数组,您可以在其中声明依赖项。前任。 smoothDicScroll 插件需要在 jquery 和 tm_ui (ui-widget) 插件之后调用。
最后你调用所有的js脚本在页脚..
worls 使用 MAMP 在本地主机上生活。在 localhost 上开发时,最好包含本地 jquery 版本的后备,因为有时您没有连接到互联网。