-1

我正在创建 jquery 幻灯片放映插件。我在 wp-content/plugin 中创建了文件夹游戏

在我的文件夹中,我有 readme.txt game.php game.css game.js

在我的game.php中,我有代码:-

<?php
/*
  Plugin Name:game
  Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
  Description: A brief description of the Plugin.
  Version: The Plugin's Version Number, e.g.: 1.0
  Author: Neeraj swarnkar
  Author URI: http://URI_Of_The_Plugin_Author
  License: A "Slug" license name e.g. GPL2
 */

/*  Copyright YEAR  PLUGIN_AUTHOR_NAME  (email : neerajswarnkar0207@gmail.com)

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

function image() {
    hello_world_html_page();
}

add_shortcode('img', 'image');

function my_scripts_method() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
    wp_enqueue_script(
            'game', 'http://localhost/guest1/wordpress/wp-content/plugins/game/game.js'/* don't hardcode your path */, array('jquery')/* this script depends on jquery, so enqueue it automatically */
    );
}

add_action('wp_enqueue_scripts', 'my_scripts_method');

function hello_world_html_page() {
    ?>
    <?php
    return '<div id="demo-top-bar">
        <div id="slideshow">
            <div><img alt="TITLE" src="img0.jpg"></div>
            <div><img alt="TITLE"src="img1.jpg"></div>
            <div><img alt="TITLE"src="img2.jpg"></div>
            <div><img alt="TITLE"src="img3.jpg"></div>
            <div>
                Pretty cool eh? This slide is proof the content can be anything.
            </div>
        </div>';
}
?>

在我的 game.js 中,我有:-

$(function() {

    $("#slideshow > div:gt(0)").hide();

    setInterval(function() { 
        $('#slideshow > div:first')
        .fadeOut(1000)
        .next()
        .fadeIn(1000)
        .end()
        .appendTo('#slideshow');
    },  3000);

});

在游戏.css

    #slideshow { 
        margin: 80px auto; 
        position: relative; 
        width: 701px; 
        height: 321px; 
        padding: 10px; 
        box-shadow: 0 0 20px rgba(0,0,0,0.4); 
    }

    #slideshow > div { 
        position: absolute; 
        top: 10px; 
        left: 10px; 
        right: 10px; 
        bottom: 10px; 
    }

当我激活并运行我的程序时..它显示 js 和 css 文件的内容..帮助我,我是 wordpress 的新手..

我已经更新了我的更改..

4

1 回答 1

1

首先是 JS
你包括 2 个 js,你自己的和 jquery。你还没有注册你赢得的脚本,你只是将它排入队列。
您可以立即入队注册。此外,我建议您合并您的 que:

function my_scripts_method() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
    wp_enqueue_script(
        'game',
        'path/to/your/js'/*don't hardcode your path*/,
        array('jquery')/*this script depends on jquery, so enqueue it automatically*/
    );
}
add_action('wp_enqueue_scripts', 'my_scripts_method');

不能解决你所有的问题,但这是一个步骤。

第二个html输出
你的html输出hello_world_html_page永远不会显示在任何地方。
get_option将从数据库中检索一个选项,它不会执行一个函数。

function image() {
    hello_world_html_page()
}
add_shortcode('img', 'image');

这更好,但仍然是错误的。
短代码不能echo,否则它会正确显示,您必须这样return做。

function hello_world_html_page() {
    return '<div id="demo-top-bar">
        <div id="slideshow">
            <div><img alt="TITLE" src="img0.jpg"></div>
            <div><img alt="TITLE"src="img1.jpg"></div>
            <div><img alt="TITLE"src="img2.jpg"></div>
            <div><img alt="TITLE"src="img3.jpg"></div>
            <div>
                Pretty cool eh? This slide is proof the content can be anything.
            </div>
        </div>';
}

第三个 CSS
你不会在任何地方排队。
如果您解决了上述两点,您应该能够处理它:

http://codex.wordpress.org/Function_Reference/wp_enqueue_style 正如@swapnesh所说,wp_enqueue_stylewp_enqueue_script

于 2012-06-01T08:41:13.433 回答