Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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 get_post_gallery_images()返回一个空数组_Php_Html_Wordpress_Shortcode - Fatal编程技术网

Php get_post_gallery_images()返回一个空数组

Php get_post_gallery_images()返回一个空数组,php,html,wordpress,shortcode,Php,Html,Wordpress,Shortcode,我有一个自定义wordpress插件,可以注册一些短代码。我想添加一个函数来使用短代码显示swiper.js滑块,但我无法实现这个范围。如果我将图库附加到页面或文章,它将不会显示,在我的函数类中返回的get\u post\u gallery\u images()数组将始终为空。我怎样才能解决这个问题?如何仅删除默认的wordpress gallery短代码,以便在附加图像中使用自己的代码 我的插件方法代码 public function imgSlider( $attr, $content )

我有一个自定义wordpress插件,可以注册一些短代码。我想添加一个函数来使用短代码显示swiper.js滑块,但我无法实现这个范围。如果我将图库附加到页面或文章,它将不会显示,在我的函数类中返回的
get\u post\u gallery\u images()
数组将始终为空。我怎样才能解决这个问题?如何仅删除默认的wordpress gallery短代码,以便在附加图像中使用自己的代码

我的插件方法代码

public function imgSlider( $attr, $content )
  {
    global $post;

    $a = shortcode_atts(array(
      'pagination' => null,
      'buttons' => null,
      'scrollbar' => null
    ), $attr);

    $images = get_post_gallery_images( $post );
    var_dump($images);
    $slider = '';

    if( $images ){
      $slider = '<div class="swiper-container">';
      $slider .= '<div class="swiper-wrapper">';
      foreach( $images as $img ){
        $slider .= '<img class="img-fluid w-100" src="'. $img .'">';
      }
      $slider .= '</div>';
      if( $a['pagination'] === true ){
        $slider .= '<div class="swiper-pagination"></div>';
      }
      if( $a['buttons'] === true ){
        $slider .= '<div class="swiper-button-prev"></div>';
        $slider .= '<div class="swiper-button-next"></div>';
      }
      $slider .= '</div>';
    }
    // This will return true
    //var_dump(has_shortcode( $post->post_content, 'gallery' )); 
    return $slider;
  }
公共函数imgSlider($attr,$content)
{
全球$员额;
$a=短码_附件(阵列)(
“分页”=>null,
“按钮”=>null,
“滚动条”=>null
),$attr);
$images=get_post_gallery_images($post);
var_dump($images);
$slider='';
如果($images){
$slider='';
$slider.='';
foreach($img形式的图像){
$slider.='';
}
$slider.='';
if($a['pagination']==true){
$slider.='';
}
如果($a['buttons']==true){
$slider.='';
$slider.='';
}
$slider.='';
}
//这将成为现实
//var_dump(有_短代码($post->post_内容,'gallery');
返回$slider;
}
这是我创建的测试页面的内容,用于调试代码并验证自定义短代码是否有效 注意:我注意到当我使用短代码时,会在html中添加一个空的
标记和一个

标记,是否可以删除它们

[bs-container type="container-fluid"]
[bs-col type="6" mobile="display"]Lorem ipsum demo shortcode[/bs-col]
[bs-col type="6" mobile="hide"]<img class="img-fluid w-100" src="https://localhost/wordpress/wp-content/uploads/2019/09/ig_testing_account_2.jpeg">[/bs-col]
[bs-col type="12" mobile="hide"]
[bs-slider pagination="true" buttons="true" scrollbar="false"][gallery link="none" size="large" ids="37,38,25"][/bs-slider]
[/bs-col]
[/bs-container]
[bs-parallax img="https://images.unsplash.com/photo-1569017436947-e1e377435a13?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=600&ixlib=rb-1.2.1&q=80&w=800" is_section="false" overlay="false"][/bs-parallax]
[bs container type=“container fluid”]
[bs col type=“6”mobile=“display”]Lorem ipsum演示快捷码[/bs col]
[bs col type=“6”mobile=“hide”][/bs col]
[bs col type=“12”mobile=“hide”]
[bs slider pagination=“true”buttons=“true”scrollbar=“false”][gallery link=“none”size=“large”ids=“37,38,25”][/bs slider]
[/bs col]
[/bs容器]
[bs视差img=”https://images.unsplash.com/photo-1569017436947-e1e377435a13?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=600&ixlib=rb-1.2.1&q=80&w=800“is_section=“false”overlay=“false”[/bs视差]