2013-04-13 38 views
3

我必須讓所有的圖像插件的選項頁博客的來源,我想提出一個插件選項頁面如下..Plz來看一下,它..如何在wordpress插件的選項頁中獲取整個博客的圖片?

public function add_plugin_page(){ 
       add_options_page('Settings Admin', 'Plugin_options', 'manage_options', 'test-setting-admin', array($this, 'create_admin_page')); 
      } 

下面的代碼是我的插件選項頁

public function create_admin_page(){ 
     ?> 
    <div class="wrap"> 

    <?php screen_icon(); ?> 

    <form action="options.php" method="post" id="<?php echo $plugin_id; ?>_options_form" name="<?php echo $plugin_id; ?>_options_form"> 

    <?php settings_fields($plugin_id.'_options'); ?> 

    <h2>kk Plugin Options &raquo; Settings</h2> 

    <table border="1" bordercolor="#FFCC00" style="background-color:#FFFFCC; margin-top:22px" width="25%" cellpadding="2" cellspacing="1"> 
     <tbody> 
     <tr> 
     <td style="padding-left:8px;font-family:Verdana, Geneva, sans-serif;color:#666;"><h3>Blog Id:</h3></td> 
     <td><p><?php echo$abc?></p></td> 
    </tr> 
    <tr> 
     <td style="padding-left:8px;font-family:Verdana, Geneva, sans-serif;color:#666;"><h3>API Key:</h3></td> 
     <td><input type="text" name="kkpo_quote" value="<?php echo get_option('kkpo_quote'); ?>" /></td> 
    </tr> 
     </tbody> 

</table> 
    <div id="mainCHImage" style="position:relative;height:'.$imgHeight.'px;width:'.$width.'px;"> 
     <img id="paletlyIcon" style="position:absolute;left:'.$imgWidth.'px;top:'.$imgHeight.'px;z-index:9999;cursor:pointer;background:none;border:none;" src="http://Images/favIcon.png" onclick="get_images()">'. 
     <img style="background:none;border:none;"></div> 


    </form> 

</div> 
    <?php 
    } 

$ ABC是,我想所有的圖像源..For,我寫了一個單獨的函數

public function get_images(){ 
    if(is_single() || is_page() || is_home()||!is_admin()){ 
    global $post; 
    global $wpdb; 

    $query_images = new WP_Query($query_images_args); 
    $images = array(); 

     foreach ($query_images->posts as $image) {  
     $images[]= wp_get_attachment_url($image->ID); 
       $abc=($images); 
       echo $abc; 
       } 

    } 


} 

但我變收到錯誤

ReferenceError: get_images is not defined 
[Break On This Error] 

get_images(); 

我已經加入該功能在我的構建,即

add_action('IMages_grab', array(&$this, 'get_images')); 
add_filter('IMages_grab', array(&$this, 'get_images')); 

回答

0

老兄,你的代碼是錯誤的這麼多層次! (我在這裏只表達我自己的意見。)

  1. 你有$query_images = new WP_Query($query_images_args);但你沒有(通過定義參數修正)規定$query_images_arg

  2. 你正在構建某種管理菜單的,但然後你把條件!is_admin(),將空一切(修正通過決定/定義,它的運作)

  3. 你有很多語法錯誤一樣echo$abc?(固定到echo $abc

    3.1。 $ abc應該是一個數組?那麼你甚至不能使用echo但print_r($abc);

  4. 您使用的是settings APi,這是序列化數組,然後調用單選項,如echo get_option('kkpo_quote');(修正決定使用哪種方法)

  5. 這是最重要的一個,爲什麼人們希望將整個網站的所有圖像都放到一個數組中,而且更重要的是,回聲呢?你能想象一個擁有10,000個圖像的網站會發生什麼?甚至只有300個圖像?

現在,您的代碼顯然是某種嘗試或練習中的剪貼&粘貼插件開發。並給出一個好的答案意味着你將不得不更好地解釋你的意圖,但你可以開始修復我在上面寫的東西,而不是完整的列表...

0

我同意@ObmerkKronen回答,但要點5。在我看來,這是問題的核心。

是的,它是有效的想要的陣列所有文章(和附件是後型)。而10K陣列可能並不那麼大,這取決於它的使用方式。

以下示例顯示一個管理員通知,其中包含指向媒體庫中所有圖像的鏈接。 Consult the Codex瞭解這裏使用的功能。應該很容易適應插件的選項頁面。

add_action('admin_notices', 'get_all_images_so_15985067'); 

function get_all_images_so_15985067() 
{ 
    // get all images 
    $args = array( 
     'post_type' => 'attachment', 
     'post_mime_type' => 'image', 
     'numberposts' => -1, 
    ); 
    $_attachments = get_posts($args); 

    // no images found, do nothing 
    if (empty($_attachments)) 
     return; 

    // build array only with IDs 
    $attachments = array(); 
    foreach ($_attachments as $key => $val) { 
     $attachments[ $val->ID ] = $_attachments[ $key ]; 
    } 

    // print thumbnail links 
    echo '<div class="updated">'; 
    foreach ($attachments as $att_id => $attachment) { 
     echo wp_get_attachment_link( 
      $att_id, 
      'thumbnail', 
      false, 
      false, 
      $attachment->post_title 
     ) . "<br>"; 
    } 
    echo '</div>'; 
} 
+1

(呵呵,我們再次見面..)請注意,我的僞反對意見不是單獨使用數組,而是因爲OP想要將它回顯到屏幕 –

相關問題