Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 编写Wordpress插件时无错误无执行_Javascript_Php_Jquery_Wordpress - Fatal编程技术网

Javascript 编写Wordpress插件时无错误无执行

Javascript 编写Wordpress插件时无错误无执行,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,以下是我的插件php代码: <html> <head> <title>Grid Demo</title> <link rel="stylesheet" href="css/style.css" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> &l

以下是我的插件php代码:

<html>
<head>
    <title>Grid Demo</title>
    <link rel="stylesheet" href="css/style.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <script src="js/fixtures.js"></script>
    <script src="js/gridList.js"></script>
    <script src="js/jquery.gridList.js"></script>
    <script src="js/load.js"></script>
</head>

<?php

/*
Plugin Name: Testingplugin
Plugin URI: http://localhost
Description: Trying plugin for the first time.
Version: 1.0
Author: AIMS
Author URI: http://localhost
License: A "Slug" license name e.g. GPL2
*/
// Exampe is from the https://www.youtube.com/watch?v=GAwPa4fP90c
add_action('admin_menu', 'myfirstpluginactions');

function myfirstpluginactions(){
    add_options_page('Title_of_the_plugin','name_of_submenu','manage_options', __FILE__,'display_menu_page');
}

function display_menu_page(){
        ?>



    <body>
    <div class="header">
        <a href="#remove-row" class="button remove-row">-</a>
        <a href="#add-row" class="button add-row">+</a>
        <p>
            <a class="github-button" href="https://github.com/hootsuite/grid" data-style="mega" data-count-href="/hootsuite/grid/stargazers" data-count-api="/repos/hootsuite/grid#stargazers_count" data-count-aria-label="# stargazers on GitHub" aria-label="Star hootsuite/grid on GitHub">GitHub</a>
        </p>
    </div>
    <div class="grid-container">
        <ul id="grid" class="grid">
            <li class="position-highlight">
                <div class="inner"></div>
            </li>
        </ul>
    </div>
    <script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>


    <?php
}

网格演示


您希望使用wp_enqueue_script()函数添加JS,然后使用plugins_url()获取JS文件的路径

添加到插件初始函数中的内容:

wp_enqueue_脚本('custom script每个脚本的新名称',plugins_url('js/fixtures.js',FILE),数组('jquery','jquery ui core'),time(),true)

wp_enqueue_样式(plugins_url('css/style.css',FILE))用于您的CSS

对插件文件夹中的每个JS文件执行上述操作。删除您添加的标题html,并且不需要使用jquery内容,因为WP会将其作为需求添加

你的职能是:

function myfirstpluginactions(){
    add_options_page('Title_of_the_plugin','name_of_submenu','manage_options', __FILE__,'display_menu_page');

wp_enqueue_style( plugins_url( 'css/style.css', FILE ) );
//Add this for each of your JS scripts
wp_enqueue_script( 'custom-script-new-name-for-each-script', plugins_url( 'js/fixtures.js', FILE ), array( 'jquery', 'jquery-ui-core' ), time(), true );

}
或者另一种方法是使用PHP包装当前代码,以获得正确的JS路径,例如更改

<script src="js/fixtures.js"></script>


您希望使用wp\u enqueue\u script()函数添加JS,然后使用plugins\u url()获取JS文件的路径

添加到插件初始函数中的内容:

wp_enqueue_脚本('custom script每个脚本的新名称',plugins_url('js/fixtures.js',FILE),数组('jquery','jquery ui core'),time(),true)

wp_enqueue_样式(plugins_url('css/style.css',FILE))用于您的CSS

对插件文件夹中的每个JS文件执行上述操作。删除您添加的标题html,并且不需要使用jquery内容,因为WP会将其作为需求添加

你的职能是:

function myfirstpluginactions(){
    add_options_page('Title_of_the_plugin','name_of_submenu','manage_options', __FILE__,'display_menu_page');

wp_enqueue_style( plugins_url( 'css/style.css', FILE ) );
//Add this for each of your JS scripts
wp_enqueue_script( 'custom-script-new-name-for-each-script', plugins_url( 'js/fixtures.js', FILE ), array( 'jquery', 'jquery-ui-core' ), time(), true );

}
或者另一种方法是使用PHP包装当前代码,以获得正确的JS路径,例如更改

<script src="js/fixtures.js"></script>


所有的js文件肯定都包括在内了吗?@proeviz我对此有点困惑。我看不出有任何错误。这意味着一切都会好起来。所有的js文件都会被包括进来吗?@proeviz对此我有点困惑。我看不出有任何错误。这意味着一切都会好起来。我到底需要在哪里补充呢?请告诉我是否有任何示例可以参考或建议更正我的代码。请在回答中添加一些详细信息,否则您可能会被否决。是否要将其添加到myfirstpluginactions()函数中。。。类似于“wp_enqueue_script”(“每个脚本的自定义脚本新名称”、plugins_url('js/fixtures.js',FILE)、array('jquery','jquery ui core')、time(),true);”还有“wp_enqueue_style(plugins_url('css/style.css',FILE));”为您的CSS。对插件文件夹中的每个JS文件执行上述操作。删除您添加的头html,并且不需要jquery内容,因为WP会将其作为一项要求添加。如果可能,请将其添加到您的答案中。我是否需要为我的代码的所有js文件重复这一行:
WP\u enqueue\u script('custom script new name for each script',plugins\u url('js/fixtures.js',FILE),array('jquery','jquery ui core'),time(),true);
?我到底需要在哪里添加它?请告诉我是否有任何示例可以参考或建议更正我的代码。请在回答中添加一些详细信息,否则您可能会被否决。是否要将其添加到myfirstpluginactions()中函数…类似于“wp_enqueue_script”(“自定义脚本每个脚本的新名称”、plugins_url('js/fixtures.js',FILE)、array('jquery'、'jquery ui core')、time()、true);“还有”wp_enqueue_style(plugins_url('css/style.css',FILE))对于你的CSS。对插件文件夹中的每个JS文件执行上述操作。删除你添加的头html,不需要jquery内容,因为WP会将其作为一项要求添加。如果可能,请将其添加到你的答案中。我是否需要对我的代码的所有JS文件重复这一行:
WP\u enqueue\u脚本('custom script new name for each script',plugins_url('js/fixtures.js',FILE),数组('jquery','jquery ui core'),time(),true);