Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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_Syntax - Fatal编程技术网

Php Wordpress语法错误,意外[

Php Wordpress语法错误,意外[,php,wordpress,syntax,Php,Wordpress,Syntax,wordpress安装有问题。当我在本地工作时,此功能正常工作: function get_images_from_media_library() { $args = array( 'post_type' => 'attachment', 'post_mime_type' =>'image', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null

wordpress安装有问题。当我在本地工作时,此功能正常工作:

function get_images_from_media_library() {
  $args = array(
    'post_type' => 'attachment',
    'post_mime_type' =>'image',
    'numberposts' => -1,
    'post_status' => null,
    'post_parent' => null, // any parent
    ); 
  $attachments = get_posts($args);
  $images = array();
  if ($attachments) {
    foreach ($attachments as $post) {
        setup_postdata($post);
        array_push($images, wp_get_attachment_image_src($post->ID, 'full')[0]);
    }
  }
  return $images;
}
这将检索安装时连接到介质的所有映像,并以数组形式返回它们

但是,当我在远程站点上安装时,当我尝试使用包含此功能的主题时,会出现以下错误:

Parse error: syntax error, unexpected '[' in /hermes/bosoraweb133/b2623/ipg.yourdomaincom/98EMcBee/wp-content/themes/98emcbee/functions.php on line 52
第52行是foreach内的这一行:

array_push($images, wp_get_attachment_image_src($post->ID, 'full')[0]);

为什么我会在远程站点而不是本地站点上出现此错误?

这是因为您使用的是仅在PHP 5.4及更高版本中可用的。您使用的是PHP 5.3或更高版本

$array = wp_get_attachment_image_src($post->ID, 'full');
array_push($images, $array[0]);

啊。那么我应该如何正确引用数组的第一个索引呢?我对PHP非常陌生。仍然适用!谢谢你4年后!