php - 将图像重用于帖子
问题描述
我正面临 WordPress 画廊帖子格式的问题。我使用此代码获取所有附加图像。它工作正常。但是在创建帖子时,它总是要求我上传新图片。我不能重复使用已经上传的图片。下面是我写的代码。
<?php
$galleries = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => 5,
'post_parent' => $post->ID,
) );
if ($galleries) :
foreach ($galleries as $gallery) : ?>
<a href="<?php the_permalink(); ?>"><img class="card-img rounded-0" src="<?php echo wp_get_attachment_url($gallery->ID); ?>" alt="<?php the_title();?>"></a>
<?php
endforeach;
endif;
?>
你能告诉我这里有什么问题吗?
解决方案
推荐阅读
- jquery - 如何修复仅在第二次单击时触发的 jQuery 函数?
- assembly - 使用堆栈指针对 MIPS 中的数组进行排序
- c# - EF Core 数据库中已经有一个名为“AspNetRoles”的对象
- python - 如何在 GitPython 中使用 GitHub 访问令牌?
- java - 无法使用 Spring Boot 应用程序连接到 Docker 映像
- php - 使用 WooCommerce wc_get_product_terms 函数对产品属性术语进行排序
- perl - 如何使用 Perl 获取网关 IP?
- javascript - 谜团:复选框正确的数组行没有被执行。错误在哪里?
- macos - 在 mac 中运行 CGAL 代码时出现编译错误
- python - 每 10 秒清空一个 Python 双端队列