【发布时间】:2014-01-02 21:21:54
【问题描述】:
我正在编写一个带有以下页面的 wordpress 小部件 1)我有母版页(master.php) - 是主插件页面 - 使用 jQuery 加载第二个页面 (slave.php) 2) 从属页面 - 有 php、jquery、css 等。 - 是一个外部页面
下面是master.php的一部分
<?php
add_action('init', 'register_masterscript');
function register_masterscript() {
wp_register_script( 'master_jquery', plugins_url('/js/master-script.js', __FILE__), array('jquery'), '2.5.1' );
wp_register_script( 'master_jquery2', plugins_url('/js/master.js', __FILE__), array('jquery'), '2.5.1' );
wp_register_style( 'master_style', plugins_url('/css/master_style.css', __FILE__), false, '1.0.0', 'all');
}
// using the registered jquery and style above
add_action('wp_enqueue_scripts', 'enqueue_masterstyle');
function enqueue_masterstyle(){
wp_enqueue_script('master_jquery');
wp_enqueue_script('master_jquery2');
wp_enqueue_style( 'master_style' );
}
?>
master.php 成功加载 slave.ph,但我的问题是 jquery 操作或链接不起作用。 由于 slave.php 是外部的,我已经尝试过
define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');
然后
<?php
add_action('init', 'register_slavescript');
function register_slavescript() {
wp_register_script( 'slave_jquery', plugins_url('/js/jQuery1.7.1.js', __FILE__), array('jquery'), '2.5.1' );
wp_register_script( 'slave_jquery2', plugins_url('/js/highlight.pack.js', __FILE__), array('jquery'), '2.5.1' );
wp_register_script( 'slave_jquery3', plugins_url('/js/combined.js', __FILE__), array('jquery'), '2.5.1' );
wp_register_style( 'slave_style', plugins_url('/css/slave_style.css', __FILE__), false, '1.0.0', 'all');
wp_register_script( 'slave_jquery4', plugins_url('/js/jquery.mousewheel.js', __FILE__), array('jquery'), '2.5.1' );
wp_register_script( 'slave_jquery5', plugins_url('/js/jquery.jscrollpane.min.js', __FILE__), array('jquery'), '2.5.1' );
}
// use the registered jquery and style above
add_action('wp_enqueue_scripts', 'enqueue_slavestyle');
function enqueue_slavestyle(){
wp_enqueue_script('slave_jquery');
wp_enqueue_script('slave_jquery2');
wp_enqueue_script('slave_jquery3');
wp_enqueue_style( 'slave_style' );
wp_enqueue_script('slave_jquery4');
wp_enqueue_script('slave_jquery5');
}
?>
看起来slave.php enqueue -ing 不起作用,我该如何以正确的方式做到这一点?
【问题讨论】:
-
文件没有加载吗?显示什么?你想通过这种主从舞蹈来达到什么目的?为什么需要加载 WordPress 两次?
-
也许很累很抱歉,但按照说明,我在问题下找不到编辑链接。由于 master.php 加载良好,并且它的链接和 jquery 功能还可以,我决定单独测试它,通过 define('WP_USE_THEMES', false);要求('../../../wp-blog-header.php'); $posts = get_posts('numberposts=10&order=ASC&orderby=post_title'); foreach ($posts as $post) : setup_postdata( $post ); ?> ”; ?>
-
使用主从我避免使用 iframe,通过使用 jquery,jQuery(document).ready(function($){ $(function() { cache: false, 127.0.0.1/livezone/wp -content/plugins/livebak3/slave.php $('#d1').html('
Loading...
').load(url); return false; }); }); -
你为什么不把它显示为一个普通的小部件呢?内联?
-
谢谢,我终于解决了我的问题,通过重新设计项目,我确保所有的 jquery 和 css 脚本都在第一页(master)上。它现在工作正常。但这是否意味着您不能在外部/自定义页面上使用 wp_equeue_script?
标签: jquery ajax wordpress jquery-plugins