2010-09-10 94 views
0

我想通過我正在創建一個插件,但我得到一個JavaScript錯誤,不能找出原因。以下是我的代碼任何幫助將不勝感激。這是我實施它的地方。 http://findlegalanswers.com/?page_id=4WordPress的插件和JQuery的

<?php 
/* 
Plugin Name: iPad and iPhone Swipe Gallery 
Version: 1.0 
Plugin URI: http://www.prototypesyndicate.com 
Description: Adds a great simple looking gallery to your pages or post with iPhone and iPad swipe. For more information on how to setup view documentation in plugin folder 
Author: Alex Gonzalez - Vinas 
Author URI: http://www.prototypesyndicate.com 
*/ 


    function jquery_load_gallery_header() { 
     echo "<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js\" type=\"text/javascript\"></script>" . "\n"; 
     echo "<script src=" . get_bloginfo('wpurl') . "/wp-content/plugins/iPad_iPhone_Gallery/js/jquery.touch-gallery-1.0.0.js\"></script>" . "\n"; 
    } 

    function simpleslide_load_ready() 
    { 
     echo "<style type=\"text/css\"> 

     #content { 
      padding: 50px 0 0 0; 
      width: 600px; 
     } 
     #gallery { 
      width: 300px; 
      overflow: hidden; 
     } 
     #gallery div, 
     #gallery a { 
      display: block; 
      float: left; 
      color: #fff; 
      width: 75px; 
      height: 75px; 
      margin: 0 8px 8px 0; 
     } 

      </style>"; 
    } 

add_action('wp_head', 'jquery_load_gallery_header'); 
add_action('wp_head', 'simpleslide_load_ready'); 


//album [album category="flickr_url"] [/album] 
function mAlbum($atts, $content = null) { 

    extract(shortcode_atts(array(
     'flickr' => 'Featured', 
    ), $atts)); 

    ob_start(); 
    ?> 

    <div id="content"> 
     <div id="gallery"> 
     </div> 
    </div> 

    <script> 
     $(function() { 
      $.getJSON("http://api.flickr.com/services/rest?method=flickr.photosets.getPhotos&api_key=ed144a125aca366df3438c58c0c0ec9d&photoset_id=72157624601158052&extras=url_sq,url_m,url_o,&format=json&jsoncallback=?", function(data) { 
       $.each(data.photoset.photo, function(i) { 
        $('<div>').append($('<img>').attr('src', this.url_sq)).data('flickr', this).appendTo('#gallery'); 
       }); 
       $('#gallery div').touchGallery({ 
        getSource: function() { 
         var f = $(this).data('flickr'); 
         return f.url_o || f.url_sq.replace('_s.', '_b.'); 
        } 
       }); 
      }); 

     }); 
    </script> 


<?php 

    $content = ob_get_contents(); 
    ob_end_clean(); 
    return $content; 

} 

// Adds shortcode to use in pages or post. 
add_shortcode('album', 'mAlbum'); 


?> 
+0

哪裏是你的功能touchGallery? – Steven 2010-09-11 16:29:59

+2

您似乎缺少第二個腳本標記的開頭引號和腳本類型。 – 2010-09-11 22:27:09

+0

請使用'plugins_url'函數(http://phpxref.ftwr.co.uk/wordpress/nav.html?wp-includes/link-template.php.source.html)代替完全硬編碼您的js文件的url #l1997)。就像'plugins_url('js/jquery.touch-gallery-1.0.0.js',__FILE__);' – mjangda 2010-09-13 14:24:53

回答

-1

我責備污染的'wpurl'返回。猜測你的博客標題設置中有一個空格,它被urlencoded變成了一個奇怪的目的地。因此,網絡瀏覽器查找:

http://blabla%20/wp-content/ ...

在任何情況下,瀏覽器被揭去的方式。檢查您的博客標題,根據需要修剪空格或以其他方式硬編碼(更好或更差)整個URL。

罪魁禍首行:

echo "<script src=" . get_bloginfo('wpurl') . "/wp-content/plugins/iPad_iPhone_Gallery/js/jquery.touch-gallery-1.0.0.js\"></script>" . "\n"; 
+0

'wpurl'返回網站的URL而不是標題。如果它被污染了,網站的其餘大部分也不會工作。此外,硬編碼網址是一個不好的主意(在公開發布插件的情況下不可行,我猜這可能是)。 – mjangda 2010-09-13 14:28:00

+0

冒着聽起來卑鄙的風險,你會混淆「應該」與「是什麼」。當時我昨天焚燒了該網站,在URL中出現了奇怪的字符編碼。 =) – pp19dd 2010-09-14 14:04:12