WordPress函数:无法从数组中获取某些值


Wordpress functions: Can't get some values from an array

我正在修改NextGen Gallery Wordpress插件中的一个类。 最终,我试图通过组装 NGG 存储在数据库中的必要位来构建图像的 URL。
我已经到了原始代码执行SQL查询并给出一个数组然后从该数组中提取某些值的地步。 该数组包含我需要的所有值,但我似乎只能获得一些值,我无法弄清楚原因。

这是我目前修改的代码:

//  Class copied from ngg plugin, change class name from 'nggWidget' to 'nggHeaderBG'
    class nggHeaderBG extends WP_Widget {
        function widget( $args, $instance ) {
           global $wpdb;
           $items   = $instance['items'];
           $exclude = $instance['exclude'];
           $list = $instance['list'];
                   $exclude_list = "AND t.gid IN ($list)";
           $imageList = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 $exclude_list ORDER by rand() limit {$items}");
           foreach($imageList as $image) {
                // get the URL constructor
                $theimage = new nggImage($image);
                // Just create the image URL
                $out .= ''.home_url().'/'.$theimage->path.'/'.$theimage->filename;
                echo $out;
        }
    }

在上面的代码中,$theimage->filename有效,但$theimage->path不起作用。 var_dump($theimage)生成以下数组(它很长,所以我将其存储在代码片段中(:

object(nggImage)#3716 (2) {
  ["_ngiw"]=>
  object(C_Image_Wrapper)#3717 (8) {
    ["_cache"]=>
    array(34) {
      ["alttext"]=>
      string(9) "homepage3"
      ["author"]=>
      string(2) "10"
      ["description"]=>
      string(1) " "
      ["errmsg"]=>
      string(0) ""
      ["error"]=>
      bool(false)
      ["exclude"]=>
      string(1) "0"
      ["filename"]=>
      string(13) "homepage3.gif"
      ["galdesc"]=>
      string(72) "For Home Landing Page Only.
Must be 880 pixels wide by 350 pixels high."
      ["galleryid"]=>
      string(1) "2"
      ["gid"]=>
      string(1) "2"
      ["hidden"]=>
      bool(false)
      ["href"]=>
      string(0) ""
      ["imagePath"]=>
      string(0) ""
      ["imageURL"]=>
      string(0) ""
      ["image_slug"]=>
      string(9) "homepage3"
      ["imagedate"]=>
      string(19) "2014-10-01 16:03:54"
      ["meta_data"]=>
      array(17) {
        ["width"]=>
        int(880)
        ["height"]=>
        int(350)
        ["full"]=>
        array(2) {
          ["width"]=>
          int(880)
          ["height"]=>
          int(350)
        }
        ["thumbnail"]=>
        array(4) {
          ["width"]=>
          int(350)
          ["height"]=>
          int(139)
          ["filename"]=>
          string(20) "thumbs_homepage3.gif"
          ["generated"]=>
          string(21) "0.25234600 1412179434"
        }
        ["aperture"]=>
        bool(false)
        ["credit"]=>
        bool(false)
        ["camera"]=>
        bool(false)
        ["caption"]=>
        bool(false)
        ["created_timestamp"]=>
        bool(false)
        ["copyright"]=>
        bool(false)
        ["focal_length"]=>
        bool(false)
        ["iso"]=>
        bool(false)
        ["shutter_speed"]=>
        bool(false)
        ["flash"]=>
        bool(false)
        ["title"]=>
        bool(false)
        ["keywords"]=>
        bool(false)
        ["saved"]=>
        bool(true)
      }
      ["name"]=>
      string(14) "second_gallery"
      ["pageid"]=>
      string(1) "0"
      ["path"]=>
      string(31) "wp-content/gallery/home_headers"
      ["permalink"]=>
      string(0) ""
      ["pid"]=>
      string(3) "411"
      ["post_id"]=>
      string(1) "0"
      ["previewpic"]=>
      string(3) "403"
      ["slug"]=>
      string(12) "home_headers"
      ["sortorder"]=>
      string(1) "0"
      ["style"]=>
      string(0) ""
      ["tags"]=>
      string(0) ""
      ["thumbFolder"]=>
      string(8) "/thumbs/"
      ["thumbPath"]=>
      string(0) ""
      ["thumbPrefix"]=>
      string(7) "thumbs_"
      ["thumbURL"]=>
      string(0) ""
      ["thumbcode"]=>
      string(0) ""
      ["title"]=>
      string(12) "Home_Headers"
    }
    ["_settings"]=>
    NULL
    ["_storage"]=>
    NULL
    ["_galleries"]=>
    NULL
    ["_orig_image"]=>
    object(stdClass)#3715 (20) {
      ["gid"]=>
      string(1) "2"
      ["name"]=>
      string(14) "second_gallery"
      ["slug"]=>
      string(12) "home_headers"
      ["path"]=>
      string(31) "wp-content/gallery/home_headers"
      ["title"]=>
      string(12) "Home_Headers"
      ["galdesc"]=>
      string(72) "For Home Landing Page Only.
Must be 880 pixels wide by 350 pixels high."
      ["pageid"]=>
      string(1) "0"
      ["previewpic"]=>
      string(3) "403"
      ["author"]=>
      string(2) "10"
      ["pid"]=>
      string(3) "411"
      ["image_slug"]=>
      string(9) "homepage3"
      ["post_id"]=>
      string(1) "0"
      ["galleryid"]=>
      string(1) "2"
      ["filename"]=>
      string(13) "homepage3.gif"
      ["description"]=>
      string(1) " "
      ["alttext"]=>
      string(9) "homepage3"
      ["imagedate"]=>
      string(19) "2014-10-01 16:03:54"
      ["exclude"]=>
      string(1) "0"
      ["sortorder"]=>
      string(1) "0"
      ["meta_data"]=>
      array(17) {
        ["width"]=>
        int(880)
        ["height"]=>
        int(350)
        ["full"]=>
        array(2) {
          ["width"]=>
          int(880)
          ["height"]=>
          int(350)
        }
        ["thumbnail"]=>
        array(4) {
          ["width"]=>
          int(350)
          ["height"]=>
          int(139)
          ["filename"]=>
          string(20) "thumbs_homepage3.gif"
          ["generated"]=>
          string(21) "0.25234600 1412179434"
        }
        ["aperture"]=>
        bool(false)
        ["credit"]=>
        bool(false)
        ["camera"]=>
        bool(false)
        ["caption"]=>
        bool(false)
        ["created_timestamp"]=>
        bool(false)
        ["copyright"]=>
        bool(false)
        ["focal_length"]=>
        bool(false)
        ["iso"]=>
        bool(false)
        ["shutter_speed"]=>
        bool(false)
        ["flash"]=>
        bool(false)
        ["title"]=>
        bool(false)
        ["keywords"]=>
        bool(false)
        ["saved"]=>
        bool(true)
      }
    }
    ["_orig_image_id"]=>
    string(3) "411"
    ["_cache_overrides"]=>
    NULL
    ["_legacy"]=>
    bool(true)
  }
  ["_propogate"]=>
  bool(true)
}

我可以得到一些变量,但不能得到其他变量。 例如,除了文件名之外,我还可以获得"alttext","pid","imagedate","image_slug","thumbFolder","thumbPrefix"。这些都有效。其他的,如"path"和"slug",我可以用来构建我的URL,总是返回值"second_gallery",即"name"值。它似乎是任何无法提取的值的默认回退。 我什至尝试过$theimage->_orig_image->path,但这没有任何效果。 使用方括号方法,即 $theimage['path']只会导致整个网站搞砸。谁能解释为什么有些值可以得到,而另一些不能? 而且,更重要的是,我如何从这个特定的数组中获取我想要的值(主要是"路径"(?谢谢。

它是

数组和对象的混合体,但忽略缓存数组,这可能是您要查找的:

$path= $theimage->_ngiw->_orig_image->path;