Wordpress图库显示附属于文章/页面的所有图片


Wordpress gallery displays all the images attached to a post/page

在我看来,Wordpress图库有一种奇怪的工作方式。我解释:

  • Wordpress图库中只显示了已被使用过的图片在当前帖子中上传。如果您在图库中添加一个图像已在媒体库中,将不会显示!

  • 创建图库后,如果我从图库中删除图像无论如何都会显示

  • 图库显示附属于该文章的所有图片(也可以是图片)特色缩略图和嵌入图像),尽管这些图像是

我认为这是一个bug。

问题:是否有可能在帖子中只显示图像(包括上传的图像和已经在媒体库中的图像),这些图像包含在画廊中?

注意:不使用短码[gallery exclude="..."],不直接从媒体库上传图像?

注:为了在帖子中显示图库,我使用以下脚本:

<ul>
<?php $images = get_children('post_type=attachment&post_mime_type=image&post_parent=' . $post->ID . '&orderby=menu_order&order=ASC');
foreach( $images as $img_id => $img_r ) :
     $thumb = wp_get_attachment_image_src( $img_id, 'thumb', true );
     $full = wp_get_attachment_image_src( $img_id, 'full', true ); ?>
     <li>
        <a href="<?php echo $full[0] ?>">
             <img src="<?php echo $thumb[0] ?>" alt="<?php echo get_the_title( $img_id ) ?>" title="<?php echo get_the_title( $img_id ) ?>">
        </a>
     </li>
<?php endforeach; ?>
</ul>

这不是bug,这就是图库的工作方式。它只会显示附在帖子上的图片,如果你想添加一个已经上传的图片到图库,那么你需要从媒体菜单中将图片附加到帖子上。

您可以使用画廊短代码来显示图像,或者您可以使用http://www.wpcodesnipps.com/display-images-attached-post/上的代码来显示图像。