1。在头脑中注册jQuery和插件
wp_register_script( \'jquery\' );
wp_register_script( \'your_jquery_plugin\', STYLESHEETPATH, \'jquery\', \'0.0\', false );
2。注册一个元框,它应该是一个简单的复选框。请按照codex page for add_meta_box() (不要在这里重复这个)。如果遵循其余部分,那么元框的$id应该是\'jquery_comments\'
.
Example (shortened):
内部functions.php
function add_jquery_comments_meta_box() {
$id = \'jquery_comments\';
$title = __( \'jQuery Comments, please?\', \'your_textdomain_string\' );
$context = \'side\'; // advanced/normal also possible
$priority = \'low\'; // high also possible
$callback_args = \'\'; // in case you want to extend it
add_meta_box( $id, $title, \'add_jquery_comments_cb_fn\', \'post\', $context, $priority, $callback_args );
}
add_action( \'admin_init\', \'add_jquery_comments_meta_box\', 1 );
// Prints the box content
// Please adjust this to your needs - only slightly modified from codex example
function add_jquery_comments_cb_fn() {
// Use nonce for verification
wp_nonce_field( basename(__FILE__), \'your_noncename\' );
// The actual fields for data entry
?>
<label for="jquery_comments"><?php _e("Do you want jquery comments on this post?", \'your_textdomain_string\' ); ?></label>
<input type="checkbox" id="jquery_comments" name="jquery_comments" />
<?php
}
3。将基于元框的脚本作为条件排队,然后在functions.php
文件
function add_jquery_comments_plugin() {
wp_enqueue_script( \'jquery\' );
wp_enqueue_script( \'your_jquery_plugin\' );
}
// and call it depending on a conditional in the comment form hook
if ( get_post_meta($post->ID, \'jquery_comments\', true) ) {
add_action( \'comment_form\', \'add_jquery_comments_plugin\' );
}