Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
Php 如何在wordpress插件的选项页面中获取整个博客的图片?_Php_Wordpress - Fatal编程技术网

Php 如何在wordpress插件的选项页面中获取整个博客的图片?

Php 如何在wordpress插件的选项页面中获取整个博客的图片?,php,wordpress,Php,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 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
    }
但我犯了一个错误

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'));

伙计,你的代码在很多方面都是错的! (我在这里只表达我自己的观点。)

  • 您有
    $query\u images=新的WP\u查询($query\u images\u args)但您没有定义
    $query\u images\u arg
    (通过定义参数进行修复)

  • 您正在构造某种类型的管理菜单,但随后您设置了
    的条件!是_admin()
    ,它将使所有内容为空(通过决定/定义其操作位置进行修复)

  • 您有许多语法错误,如
    echo$abc?
    (修复为
    echo$abc

    3.1$abc应该是一个数组吗?然后你甚至不能使用echo,而是
    print\r($abc)

  • 您使用的是
    设置APi
    ,它是序列化数组,然后调用单个选项,如
    echo get_选项('kkpo_quote')(修复程序决定使用哪种方法)

  • 这是最重要的一个,为什么在地球上会有人想把整个网站的所有图像都放到一个数组中,而且更进一步,回声它??你能想象一个拥有10000张甚至只有300张图片的网站会发生什么吗


  • 现在,您的代码显然是剪切粘贴插件开发中的某种尝试或练习。给出一个好的答案意味着你必须更好地解释你的意图,但你可以从修正我在上面写的内容开始,而不是完整的列表…

    我同意@ObmerkKronen的大部分答案,但有点
    5
    。在我看来,这是问题的核心

    是的,想要一个包含所有帖子的数组是有效的(附件是一种帖子类型)。而10K阵列可能没有那么大,这取决于它的使用方式

    以下示例显示一个管理通知,其中包含指向媒体库中所有图像的链接。了解这里使用的函数。这应该很容易适应插件的选项页面

    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>';
    }
    
    add_action('admin_notices'、'get_all_images_so_15985067');
    函数get_all_images_so_15985067()
    {
    //获取所有图像
    $args=数组(
    “post_类型”=>“附件”,
    “post_mime_type”=>“image”,
    “numberposts”=>-1,
    );
    $\u attachments=get\u posts($args);
    //未找到图像,请不要执行任何操作
    如果(空($\附件))
    返回;
    //仅使用ID构建阵列
    $attachments=array();
    foreach($\附件为$key=>$val){
    $attachments[$val->ID]=$\附件[$key];
    }
    //打印缩略图链接
    回声';
    foreach($att_id=>$attachment形式的附件){
    echo wp_获取附件_链接(
    $att_id,
    “缩略图”,
    假,,
    假,,
    $attachment->post_title
    ).“
    ”; } 回声'; }
    (呵呵,我们又见面了……)请注意,我的伪反对意见不是数组本身的使用,而是OP希望将其回显到屏幕上
    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>';
    }