首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >本机图库自定义html输出

本机图库自定义html输出
EN

WordPress Development用户
提问于 2018-09-14 12:35:15
回答 1查看 117关注 0票数 0

我已经通过Add媒体>创建图片库将图片库添加到页面中。我不想输出库的默认html,也不想改变图库排序码的属性:itemtagicontagcaptiontag,因为我想要一个完全自定义的html。

我尝试过滤post_gallery,抓取作为图库包含到页面中的图像的urls,并输出它们:

代码语言:javascript
复制
add_filter( 'post_gallery', 'my_name_page_gallery', 10, 2 );
function my_name_page_gallery($output, $attr) {
    $output = get_post_gallery_images();
    return $output;
}

但我得到了以下错误:

达到最大功能嵌套级别‘512’,中止!在第234行中包含/unccodes.php

我做错了什么?如何获得图片库图像的urls并输出自定义html?

EN

回答 1

WordPress Development用户

发布于 2018-09-14 13:25:17

这就是你想要的吗,这里get_post_gallery_images()

这是该页的示例。

代码语言:javascript
复制
add_filter( 'the_content', 'wpdocs_show_gallery_image_urls' );

/**
* Show image URLs below the content
*/
function wpdocs_show_gallery_image_urls( $content ) {

    global $post;

    // Only do this on singular items
    if( ! is_singular() )
        return $content;

    // Make sure the post has a gallery in it
    if( ! has_shortcode( $post->post_content, 'gallery' ) )
        return $content;

    // Retrieve the first gallery in the post
    $gallery = get_post_gallery_images( $post );
    $image_list = '';

    // Loop through each image in each gallery
    foreach( $gallery as $image_url ) {
        $image_list .= '' . '' . '';
    }
    $image_list .= '';

    // Append our image list to the content of our post
    $content .= $image_list;

    return $content;
}
票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/314205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档