Wordpress:get_post_gallery图像自定义大小
我试图手动显示post gallery,但是图像大小调整为默认缩略图大小,这太小了。我正在开发一个主题,我想在将来出售,所以我想以自定义大小显示图库中的图像,忽略wordpress设置。我该怎么做 这是我的密码:Wordpress:get_post_gallery图像自定义大小,wordpress,post,gallery,Wordpress,Post,Gallery,我试图手动显示post gallery,但是图像大小调整为默认缩略图大小,这太小了。我正在开发一个主题,我想在将来出售,所以我想以自定义大小显示图库中的图像,忽略wordpress设置。我该怎么做 这是我的密码: if ( get_post_gallery() ) : $gallery = get_post_gallery( get_the_ID(), false ); foreach( $gallery['src'] AS $src ) { ?>
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
foreach( $gallery['src'] AS $src )
{
?>
<li data-thumb="<?php echo $src; ?>">
<img src="<?php echo $src; ?>" alt="Gallery image" />
</li>
<?php
}
endif;
if(get\u post\u gallery()):
$gallery=get_post_gallery(get_ID(),false);
foreach($src][src']作为$src)
{
?>
在调用该库之前,您可以使用筛选器对shortcode\u atts\u gallery
进行操作
add_filter('shortcode_atts_gallery','force_large_images',10,3);
function force_large_images($out, $pairs, $atts) {
$out['size'] = 'my_size'; // for example, "large"
return $out;
}
如果您不再需要该过滤器,请不要忘记将其移除
remove_filter('shortcode_atts_gallery','force_large_images',10,3);
另一种方法是执行您自己的查询
$args = array( 'post_mime_type' => 'image', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'order' => 'ASC');
$attachments = get_children($args);
foreach( $attachments as $attachment) {
if ( !empty($attachment->guid ) ) {
$img_url = wp_get_attachment_image_src($attachment->ID, 'full'); //change *full* size with your custom size
// and then do something ..
}
很有魅力。谢谢!嗯,我刚刚注意到了一件事。如果我的图库中有多张图片,上面的代码只对第一张图片有效。第二张图片没有我想要的自定义尺寸(1144x680)。怎么了?顺便说一句,我用的是你发布的最后一种方法。