我正在自定义此主题。我正在使用get_the_gallery()
函数从自定义帖子中获取图库。我可以这样做,但当库插入到短代码之间时。。。
对于eg:
[two-third]
[gallery ids="18,17,8,7,6"]
[/two-third]
那我就没法去画廊了。。我正在使用以下代码
<?php
if ( get_post_gallery() ):
$gallery = get_post_gallery( $post, false );
$w3_ids = explode( ",", $gallery[\'ids\'] );
?>
<?php
$gallery_count=1;
foreach( $w3_ids AS $w3_id ):
$src = wp_get_attachment_image_src($w3_id,\'full\');
?>
<div class="item <?php if($gallery_count==1)echo "active"; ?>">
<img src="<?php echo $src[0]; ?>" alt="" />
</div>
<?php
$gallery_count++;
endforeach;
endif;
?>
可以做什么。。。请帮忙
最合适的回答,由SO网友:terminator 整理而成
我不知道为什么代码不起作用。但我就是这样做的这可能对像我这样的noob有帮助
<?php
$name = get_the_content();
preg_match(\'/\\[gallery ids="([^]]*)\\"]/\', $name, $match);
$w3_ids = explode( ",", $match[1] );
$gallery_count=1;
foreach( $w3_ids AS $w3_id ):
$src = wp_get_attachment_image_src($w3_id,\'full\');
?>
<div class="item <?php if($gallery_count==1)echo "active"; ?>">
<img src="<?php echo $src[0]; ?>" alt="" />
</div>
<?php
$gallery_count++;
endforeach;
?>