0

我可以在我的 wordpress 插件中使用第三方 jquery 插件吗?找不到任何关于此的内容。结构会是什么样子?我会像在主题中工作一样将脚本排入队列吗?我对wordpress很陌生。

我的插件是否还需要一个 doctype 和一个 head 标签以及所有这些?我猜不是?

我正在尝试采用非 wordpress 脚本并将其转换为插件。这是我的代码,我正在使用这个第 3 方插件 - http://filamentgroup.com/lab/update_to_jquery_visualize_accessible_charts_with_html5_from_designing_with/

<?php

/*

插件名称:Crashboard

描述:碰撞测试

版本:0.3

作者:模糊逻辑

许可证:GPL2

*/

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CrashBoard</title>
<link href="css/basic.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://filamentgroup.github.com/EnhanceJS/enhance.js"></script> 
<script type="text/javascript" src='js/visualize.jQuery.js'></script>
<link href='css/visualize.css' type="text/css" rel="stylesheet" />     
<link href='css/visualize-light.css' type="text/css" rel="stylesheet" />    
<style>
#chart{
    display: none;
}

#chart7{
    display: none;
}

#gross{
    display: none;
}

#gross7{
    display: none;
}

#table_2 {
margin-left: 550px;
margin-top: -668px;
margin-bottom: 474px;
}

#sevenchart {
margin-left: 520px;
margin-top: -450px;
}

#sevengross{
margin-left: 260px;
margin-top: -30px;
}

#thirtychart {
margin-top: -38px;
margin-left: 22px;
}

#thirtygross {
margin-top: -38px;
margin-left: 22px;
margin-bottom: 15px;
}

#chart thead, td{
min-width: 60px;
}
</style>            
<script type="text/javascript">            
    $(document).ready(function(){

        $('#table').visualize({type: 'area', width: 950, height: 270}).appendTo('#thirtychart');

    });
</script>
</head>
<body>
<br/>
<table id="table">
<caption>30 Day Sales Overview</caption>
<thead>
    <tr>
        <td></td>
        <th scope="col">Units Sold</th>
        <th scope="col">Total Value Sold</th>
        <th scope="col">Total Clicks from Referrals</th>
        <th scope="col">Total Referrals to Sales</th>
        <th scope="col">Total commission Paid Out</th>
    </tr>
  </thead>
  <tbody>
    <tr>
        <?php

        global $wpdb;

        $y='';

        for($i=30; $i>=0; $i--){

            $the_time = time() - ($i * 24 * 60 * 60);

            $the_date = date('m-d', $the_time);

            echo "<th scope=\"row\">" . $the_date . "</th>";

            $day_quant = '';

            $day_gross = '';

            $day_clicks = '';

            $day_completes = '';

            $day_payments = '';

            $iminus1 = '';

            $iminus1 = $i-1;

            $ipn_list = $wpdb->get_results("Select * FROM paypal_ipn WHERE paypal_date >= DATE_SUB(NOW(), INTERVAL $i day) AND paypal_date <= DATE_SUB(NOW(), INTERVAL $iminus1 day)");

            if($ipn_list!=null){

                foreach( $ipn_list as $ipn_data ){

                    $order_quant = $ipn_data->quantity;

                    $day_quant += $order_quant; 

                    $order_gross = $ipn_data->payment_gross;

                    $day_gross += $order_gross; 

                }

                echo "<td>" . $day_quant . "</td>";
                echo "<td>" . $day_gross . "</td>";  


            }else{

                echo "<td>0</td>"; 
                echo "<td>0</td>";  

            }

            $affiliate_list = $wpdb->get_results("Select * FROM wp_affiliatedata WHERE paypal_date >= DATE_SUB(NOW(), INTERVAL $i day) AND paypal_date <= DATE_SUB(NOW(), INTERVAL $iminus1 day)");

            if($affiliate_list!=null){

                foreach( $affiliate_list as $affiliate_data ){

                    $refer_clicks = $affiliate_data->uniques;

                    $day_clicks += $refer_clicks;   

                    $refer_completes = $affiliate_data->completes;

                    $day_completes += $refer_completes; 

                    $refer_payments = $affiliate_data->payments;

                    $day_payments += $refer_payments;   

                }               

                echo "<td>" . $day_clicks . "</td>";
                echo "<td>" .  $day_completes . "</td>";
                echo "<td>" .  $day_payments . "</td>";   

            }else{

                echo "<td>0</td>";
                echo "<td>0</td>";
                echo "<td>0</td>"; 
                echo "</tr>";   

            }


            }
        ?>

</tbody>
</table>

我想让它成为一个仪表板小部件,所以从我所见,我需要将主脚本放入 1 个函数并注册该函数..但是如果有的话,第三方 jquery 和 css 将如何适应呢?非常感谢您提前提供的帮助!

4

1 回答 1

0

惊人的文章,找到了我正在寻找的一切 - http://www.jdmweb.com/resources/jquery_to_wordpress_plugin

这是我需要使用 Fancybox 作为示例 3rd-party jquery 插件的代码:

//Group the code inside a function
function fancybox_wp_setup(){
  wp_enqueue_style(
  "jquery.fancybox", WP_PLUGIN_URL."/jQuery2Wp_fancybox/jquery.fancybox-1.3.1.css", 
  false, "1.3.1");

  wp_enqueue_script("jquery");

  wp_enqueue_script(
  "jquery.fancybox", WP_PLUGIN_URL."/jQuery2Wp_fancybox/jquery.fancybox.js", 
  array("jquery"), "1.3.1",1);  

  wp_enqueue_script(
  "jquery.fancyboxsetup", WP_PLUGIN_URL."/jQuery2Wp_fancybox/fancybox-setup.js", 
  array("jquery","jquery.fancybox"), "",1);
}
于 2012-08-27T10:48:34.897 回答