在WP codex中搜索时,我找到了此函数:
function pw_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 all galleries of this post
$galleries = get_post_galleries_images( $post );
$image_list = \'\';
// Loop through all galleries found
foreach( $galleries as $gallery ) {
// Loop through each image in each gallery
foreach( $gallery as $image ) {
$image_list .= \'<div><img src="\' . $image . \'" ></div>\';
}
}
$image_list .= \'\';
// Append our image list to the content of our post
$content .= $image_list;
return $content;
}
// add_filter( \'the_content\', \'pw_show_gallery_image_urls\' );
在原始代码中,返回的是列表中的图像URL。我做了一点调整,以创建使用Slick Slider创建幻灯片所需的结构。现在我试图在我的单{slug}中输出这个函数。php将库中的所有图像包装在一个div中。
我试过:
<div class="slider">
<?php pw_show_gallery_image_urls( get_the_content() ); ?>
</div>
以及:<div class="slider">
<?php pw_show_gallery_image_urls( $content ); ?>
</div>
函数需要一个参数,但我不知道是什么。