我使用了@HOWDY\\u MCGEE的答案中的一个函数,再加上一些重写,附件是我的工作代码。
功能。php:
function pw_show_gallery_image_urls() {
global $post;
// Make sure the post has a gallery in it
if( ! has_shortcode( $post->post_content, \'gallery\' ) )
// return $content;
return \'nadagif\';
// Retrieve the first gallery in the post
$gallery = get_post_gallery_images( $post );
$image_list = \'<ul class="slideshow">\';
// Loop through each image in each gallery
foreach( $gallery as $image_url ) {
$image_list .= \'<li>\' . \'<img src="\' . $image_url . \'">\' . \'</li>\';
}
$image_list .= \'</ul>\';
return $image_list;
}
function strip_shortcode_gallery( $content ) {
preg_match_all( \'/\'. get_shortcode_regex() .\'/s\', $content, $matches, PREG_SET_ORDER );
if ( ! empty( $matches ) ) {
foreach ( $matches as $shortcode ) {
if ( \'gallery\' === $shortcode[2] ) {
$pos = strpos( $content, $shortcode[0] );
if ($pos !== false)
return substr_replace( $content, \'\', $pos, strlen($shortcode[0]) );
}
}
}
return $content;
}
function pw_content_with_gallery_list() {
global $post;
// 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 = \'<ul class="slideshow">\';
// Loop through each image in each gallery
foreach( $gallery as $image_url ) {
$image_list .= \'<li>\' . \'<img src="\' . $image_url . \'">\' . \'</li>\';
}
$image_list .= \'</ul>\';
// Append our image list to the content of our post
$content = strip_shortcode_gallery(get_the_content());
$content = $image_list . $content;
return $content;
}
然后是格式。php,我可以做以下事情:
<section class="entry-images cf" itemprop="articleBody">
<?php echo pw_show_gallery_image_urls(); ?>
</section> <?php // end images section ?>
以及
<section class=\'entry-content\'>
<?php the_content(); ?>
</section>
如果有人想到更好的解决方案,我很乐意了解他们。