Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.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/1/wordpress/11.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_Image_Image Gallery - Fatal编程技术网

Php 替换Wordpress图像库

Php 替换Wordpress图像库,php,wordpress,image,image-gallery,Php,Wordpress,Image,Image Gallery,因为我的最后一个问题很快就得到了回答,我想我还是再试试运气吧 我正在尝试在我创建的自定义帖子类型中创建一个图库。我希望能够通过wordpress管理编辑器将图片/图库添加到帖子中,但随后会有一个功能,即拉取图片,将其包装在div中,并用新图片替换现有的图库 我想这样做,因为我希望图像适合不同大小的图像网格。例如,图像1为全宽,图像2为半宽,图像3为四分之一,依此类推 我试过两种方法,一种是带孩子 我在get_post_gallery方面没有取得多大进展,但我知道我必须使用wp_get_attac

因为我的最后一个问题很快就得到了回答,我想我还是再试试运气吧

我正在尝试在我创建的自定义帖子类型中创建一个图库。我希望能够通过wordpress管理编辑器将图片/图库添加到帖子中,但随后会有一个功能,即拉取图片,将其包装在div中,并用新图片替换现有的图库

我想这样做,因为我希望图像适合不同大小的图像网格。例如,图像1为全宽,图像2为半宽,图像3为四分之一,依此类推

我试过两种方法,一种是带孩子

我在get_post_gallery方面没有取得多大进展,但我知道我必须使用wp_get_attachment_url来获取完整大小的图像,而不是缩略图

现在,有两个问题:

我对数组有点困惑,那我该怎么做呢 选择数组中的第一个图像,并使用 类image large,然后是第二个图像,并将其包装为 带类图像介质的div

如何替换通过编辑器添加的库/图像 有新的画廊/图片吗?现在,我得到了两个 图像、通过编辑器添加的原始图像以及 通过函数获得

编辑

我想我解决了第一个问题。仔细阅读关联数组,发现您可以执行类似echo$gallery['src'][0]的操作;获取每个图像的源url。但仍然对问题2感到困惑。

解决了

//Remove original Gallery
function remove_the_first_gallery( $output, $attr ){
    $output = '<!-- gallery 1 was here -->';   // Must be non-empty.
    return $output;
}

add_filter( 'post_gallery', 'remove_the_first_gallery' );
删除了页面上的所有库。但由于我的新画廊从技术上讲不是一个post_画廊,所以它被单独留下了

$gallery = get_post_gallery( get_the_ID(), false );

            /* Loop through all the image and output them one by one */
            foreach( $gallery['src'] AS $src )
            {
                ?>
                <div class="project-img">
                <img src="<?php echo $src; ?>" alt="Gallery image" />
                </div>
                <?php
            }
//Remove original Gallery
function remove_the_first_gallery( $output, $attr ){
    $output = '<!-- gallery 1 was here -->';   // Must be non-empty.
    return $output;
}

add_filter( 'post_gallery', 'remove_the_first_gallery' );