我已经通过Add媒体>创建图片库将图片库添加到页面中。我不想输出库的默认html,也不想改变图库排序码的属性:itemtag、icontag、captiontag,因为我想要一个完全自定义的html。
我尝试过滤post_gallery,抓取作为图库包含到页面中的图像的urls,并输出它们:
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?
发布于 2018-09-14 13:25:17
这就是你想要的吗,这里?get_post_gallery_images()。
这是该页的示例。
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;
}https://wordpress.stackexchange.com/questions/314205
复制相似问题