Function Reference/wp enqueue script:修订间差异
来自站长百科
(新页面: == Description == A safe way of adding javascripts to a WordPress generated page. == Usage == %%%<?php wp_enqueue_script( 'handle', 'src', 'deps', 'ver'); ?>%%% == Example == === Usa...) |
无编辑摘要 |
||
第1行: | 第1行: | ||
== Description == | == Description == | ||
==描述== | |||
A safe way of adding javascripts to a WordPress generated page. | A safe way of adding javascripts to a WordPress generated page. | ||
添加javascript到WordPress产生的网页的一种安全的方式。 | |||
== Usage == | |||
== 用法 == | |||
%%%<?php wp_enqueue_script( 'handle', 'src', 'deps', 'ver'); ?>%%% | |||
%%%<?php wp_enqueue_script( 'handle', 'src', 'deps', 'ver'); ?>%%% | %%%<?php wp_enqueue_script( 'handle', 'src', 'deps', 'ver'); ?>%%% | ||
== Example == | == Example == | ||
== 例子 == | |||
=== Usage === | === Usage === | ||
=== 用法 === | |||
Load the scriptaculous script: | Load the scriptaculous script: | ||
载入scriptaculous脚本: | |||
<?php wp_enqueue_script('scriptaculous'); ?> | <?php wp_enqueue_script('scriptaculous'); ?> | ||
<?php wp_enqueue_script('scriptaculous'); ?> | |||
Add and load a new script that depends on scriptaculous (this will also cause it to load scriptaculous into the page as well): | Add and load a new script that depends on scriptaculous (this will also cause it to load scriptaculous into the page as well): | ||
添加并且载入一个新的脚本,取决于scriptaculous(这也会导致其向页面载入scriptaculous): | |||
<?php wp_enqueue_script('newscript', | <?php wp_enqueue_script('newscript', | ||
'/wp-content/plugins/someplugin/js/newscript.js', | |||
array('scriptaculous'), | |||
'1.0' ); ?> | |||
<?php wp_enqueue_script('newscript', | |||
'/wp-content/plugins/someplugin/js/newscript.js', | '/wp-content/plugins/someplugin/js/newscript.js', | ||
array('scriptaculous'), | array('scriptaculous'), | ||
第21行: | 第43行: | ||
== Parameters == | == Parameters == | ||
== 参数 == | |||
; handle : (''string'') Name of the script. Lowercase string. | ; handle : (''string'') Name of the script. Lowercase string. | ||
; handle : (''string'') 脚本名称。小写字母字符串。 | |||
; src: (''string'') (Optional) Path to the script from the root directory of WordPress. Example: "/wp-includes/js/scriptaculous/scriptaculous.js". This parameter is only required when WordPress does not already know about this script. Defaults to false. | ; src: (''string'') (Optional) Path to the script from the root directory of WordPress. Example: "/wp-includes/js/scriptaculous/scriptaculous.js". This parameter is only required when WordPress does not already know about this script. Defaults to false. | ||
; src: (''string'') (Optional)打到WordPress根目录的脚本的路径。例如:"/wp-includes/js/scriptaculous/scriptaculous.js"。只有WordPress不了解这个脚本的时候,才会使用这个参数。默认为错误的。 | |||
; deps: (''array'') (Optional) Array of handles of any script that this script depends on; scripts that must be loaded before this script. false if there are no dependencies. This parameter is only required when WordPress does not already know about this script. Defaults to false. | ; deps: (''array'') (Optional) Array of handles of any script that this script depends on; scripts that must be loaded before this script. false if there are no dependencies. This parameter is only required when WordPress does not already know about this script. Defaults to false. | ||
; deps: (''array'') (Optional)处理这个脚本依赖的任何脚本的数组;脚本必须在这个脚本之前载入。如果没有依赖,就返回错误的。只有WordPress不了解这个脚本的时候,才会使用这个参数。默认为错误的。 | |||
; ver : (''string'') (Optional) String specifying the script version number, if it has one. Defaults to false. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the script. | ; ver : (''string'') (Optional) String specifying the script version number, if it has one. Defaults to false. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the script. | ||
; ver : (''string'') (Optional)如果脚本拥有版本数字,这个字符串做了规定。这个参数用来确保不考虑缓存,向client发送了正确的版本,因此如果拥有版本数字,就应该包含而且对脚本有重要意义。 | |||
Default scripts included with WordPress: | Default scripts included with WordPress: | ||
WordPress中包含的默认脚本: | |||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
第102行: | 第136行: | ||
| thickbox | | thickbox | ||
|} | |} | ||
{| class="wikitable" | |||
|- | |||
! Script Name | |||
! Handle | |||
|- | |||
| [http://www.brothercake.com/ Docking Boxes] | |||
| dbx | |||
|- | |||
| [http://www.axentric.com/aside/fat/ Fade Anything Technique] | |||
| fat | |||
|- | |||
| [http://www.twilightuniverse.com Simple AJAX Code-Kit] | |||
| sack | |||
|- | |||
| [http://www.alexking.org QuickTags] | |||
| quicktags | |||
|- | |||
| [http://mattkruse.com ColorPicker] | |||
| colorpicker | |||
|- | |||
| [http://tinymce.moxiecode.com/ Tiny MCE] | |||
| tiny_mce | |||
|- | |||
| [http://wordpress.org/tags/tinymce WordPress Tiny MCE] | |||
| wp_tiny_mce | |||
|- | |||
| [http://www.prototypejs.org/ Prototype Framework] | |||
| prototype | |||
|- | |||
| Autosave | |||
| autosave | |||
|- | |||
| WordPress AJAX | |||
| wp-ajax | |||
|- | |||
| List Manipulation | |||
| listman | |||
|- | |||
| [http://www.script.aculo.us Scriptaculous Root] | |||
| scriptaculous-root | |||
|- | |||
| [http://www.script.aculo.us Scriptaculous Builder] | |||
| scriptaculous-builder | |||
|- | |||
| [http://www.script.aculo.us Scriptaculous Drag & Drop] | |||
| scriptaculous-dragdrop | |||
|- | |||
| [http://www.script.aculo.us Scriptaculous Effects] | |||
| scriptaculous-effects | |||
|- | |||
| [http://www.script.aculo.us Scriptaculous Slider] | |||
| scriptaculous-slider | |||
|- | |||
| [http://www.script.aculo.us Scriptaculous Controls] | |||
| scriptaculous-controls | |||
|- | |||
| [http://www.script.aculo.us Scriptaculous] | |||
| scriptaculous | |||
|- | |||
| [http://www.defusion.org.uk/ Image Cropper] | |||
| cropper | |||
|- | |||
| [http://swfupload.org/ SWFUpload] | |||
| swfpload | |||
|- | |||
| [http://jquery.com/ jQuery] | |||
| jquery | |||
|- | |||
| [http://jquery.com/demo/thickbox/ ThickBox] | |||
| thickbox | |||
|} | |||
==Resources== | ==Resources== | ||
==资源== | |||
* [http://nickohrn.com/loading-javascript-libraries-in-wordpress-plugins-with-wp_enqueue_script/ Loading Javascript Libraries in Wordpress Plugins with wp_enqueue_script()] | * [http://nickohrn.com/loading-javascript-libraries-in-wordpress-plugins-with-wp_enqueue_script/ Loading Javascript Libraries in Wordpress Plugins with wp_enqueue_script()] | ||
*[http://planetozh.com/blog/2008/04/how-to-load-javascript-with-your-wordpress-plugin/ How To: Load Javascript With Your WordPress Plugin] | *[http://planetozh.com/blog/2008/04/how-to-load-javascript-with-your-wordpress-plugin/ How To: Load Javascript With Your WordPress Plugin] | ||
第110行: | 第248行: | ||
*[http://www.devlounge.net/articles/using-javascript-and-css-with-your-wordpress-plugin Using JavaScript and CSS with your WordPress Plugin] | *[http://www.devlounge.net/articles/using-javascript-and-css-with-your-wordpress-plugin Using JavaScript and CSS with your WordPress Plugin] | ||
* [http://www.lost-in-code.com/47/wordpress-using-javascript-libraries-with-your-plugin-or-theme/ Using Javascript libraries with your Wordpress plugin or theme] | * [http://www.lost-in-code.com/47/wordpress-using-javascript-libraries-with-your-plugin-or-theme/ Using Javascript libraries with your Wordpress plugin or theme] | ||
[http://nickohrn.com/loading-javascript-libraries-in-wordpress-plugins-with-wp_enqueue_script/ Loading Javascript Libraries in Wordpress Plugins with wp_enqueue_script()] | |||
*[http://planetozh.com/blog/2008/04/how-to-load-javascript-with-your-wordpress-plugin/ 怎样: 使用WordPress插件载入Javascript] | |||
*[http://noteslog.com/post/how-to-load-javascript-in-wordpress-plugins/怎样在WordPress插件中载入Javascript] | |||
*[http://comox.textdrive.com/pipermail/wp-hackers/2008-March/018979.html wp_enqueue_script question on wp-hackers] | |||
*[http://www.devlounge.net/articles/using-javascript-and-css-with-your-wordpress-plugin 用WordPress插件使用JavaScript 和 CSS] | |||
* [http://www.lost-in-code.com/47/wordpress-using-javascript-libraries-with-your-plugin-or-theme/ 用WordPress插件或者主题使用Javascript libraries] |
2008年7月31日 (四) 16:27的版本
Description
描述
A safe way of adding javascripts to a WordPress generated page. 添加javascript到WordPress产生的网页的一种安全的方式。
Usage
用法
%%%<?php wp_enqueue_script( 'handle', 'src', 'deps', 'ver'); ?>%%%
%%%<?php wp_enqueue_script( 'handle', 'src', 'deps', 'ver'); ?>%%%
Example
例子
Usage
用法
Load the scriptaculous script:
载入scriptaculous脚本:
<?php wp_enqueue_script('scriptaculous'); ?>
<?php wp_enqueue_script('scriptaculous'); ?>
Add and load a new script that depends on scriptaculous (this will also cause it to load scriptaculous into the page as well):
添加并且载入一个新的脚本,取决于scriptaculous(这也会导致其向页面载入scriptaculous):
<?php wp_enqueue_script('newscript', '/wp-content/plugins/someplugin/js/newscript.js', array('scriptaculous'), '1.0' ); ?>
<?php wp_enqueue_script('newscript',
'/wp-content/plugins/someplugin/js/newscript.js', array('scriptaculous'), '1.0' ); ?>
Parameters
参数
- handle
- (string) Name of the script. Lowercase string.
- handle
- (string) 脚本名称。小写字母字符串。
- src
- (string) (Optional) Path to the script from the root directory of WordPress. Example: "/wp-includes/js/scriptaculous/scriptaculous.js". This parameter is only required when WordPress does not already know about this script. Defaults to false.
- src
- (string) (Optional)打到WordPress根目录的脚本的路径。例如:"/wp-includes/js/scriptaculous/scriptaculous.js"。只有WordPress不了解这个脚本的时候,才会使用这个参数。默认为错误的。
- deps
- (array) (Optional) Array of handles of any script that this script depends on; scripts that must be loaded before this script. false if there are no dependencies. This parameter is only required when WordPress does not already know about this script. Defaults to false.
- deps
- (array) (Optional)处理这个脚本依赖的任何脚本的数组;脚本必须在这个脚本之前载入。如果没有依赖,就返回错误的。只有WordPress不了解这个脚本的时候,才会使用这个参数。默认为错误的。
- ver
- (string) (Optional) String specifying the script version number, if it has one. Defaults to false. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the script.
- ver
- (string) (Optional)如果脚本拥有版本数字,这个字符串做了规定。这个参数用来确保不考虑缓存,向client发送了正确的版本,因此如果拥有版本数字,就应该包含而且对脚本有重要意义。
Default scripts included with WordPress:
WordPress中包含的默认脚本:
Script Name | Handle |
---|---|
Docking Boxes | dbx |
Fade Anything Technique | fat |
Simple AJAX Code-Kit | sack |
QuickTags | quicktags |
ColorPicker | colorpicker |
Tiny MCE | tiny_mce |
WordPress Tiny MCE | wp_tiny_mce |
Prototype Framework | prototype |
Autosave | autosave |
WordPress AJAX | wp-ajax |
List Manipulation | listman |
Scriptaculous Root | scriptaculous-root |
Scriptaculous Builder | scriptaculous-builder |
Scriptaculous Drag & Drop | scriptaculous-dragdrop |
Scriptaculous Effects | scriptaculous-effects |
Scriptaculous Slider | scriptaculous-slider |
Scriptaculous Controls | scriptaculous-controls |
Scriptaculous | scriptaculous |
Image Cropper | cropper |
SWFUpload | swfpload |
jQuery | jquery |
ThickBox | thickbox |
Script Name | Handle |
---|---|
Docking Boxes | dbx |
Fade Anything Technique | fat |
Simple AJAX Code-Kit | sack |
QuickTags | quicktags |
ColorPicker | colorpicker |
Tiny MCE | tiny_mce |
WordPress Tiny MCE | wp_tiny_mce |
Prototype Framework | prototype |
Autosave | autosave |
WordPress AJAX | wp-ajax |
List Manipulation | listman |
Scriptaculous Root | scriptaculous-root |
Scriptaculous Builder | scriptaculous-builder |
Scriptaculous Drag & Drop | scriptaculous-dragdrop |
Scriptaculous Effects | scriptaculous-effects |
Scriptaculous Slider | scriptaculous-slider |
Scriptaculous Controls | scriptaculous-controls |
Scriptaculous | scriptaculous |
Image Cropper | cropper |
SWFUpload | swfpload |
jQuery | jquery |
ThickBox | thickbox |
Resources
资源
- Loading Javascript Libraries in Wordpress Plugins with wp_enqueue_script()
- How To: Load Javascript With Your WordPress Plugin
- How to load JavaScript in WordPress plugins
- wp_enqueue_script question on wp-hackers
- Using JavaScript and CSS with your WordPress Plugin
- Using Javascript libraries with your Wordpress plugin or theme
Loading Javascript Libraries in Wordpress Plugins with wp_enqueue_script()