我正在尝试在中显示附加到帖子的图像single.php
我使用过:
<?php if (have_posts()) : while(have_posts()) : the_post(); ?>
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
\'post_status\' => \'any\',
\'post_parent\' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) : ?>
<ul class="portfolio-image-list">
<?php foreach($attachments as $attachment): ?>
<li class="box">
<figure>
<?php the_attachment_link($attachment->ID, true); ?>
<figcaption><?php echo $attachment->post_title; ?></figcaption>
</figure>
</li>
<?php endforeach; ?>
</ul>
<?php else : ?>
<p>No images found for this post.</p>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
然而,该图像似乎在帖子内容中(经确认
var_dump($post)
并且没有附件
var_dump($attachments)
给我一个空数组。
我好像误解了什么。。。
var_dump($post);
给我:
object(WP_Post)#136 (25) {
["ID"]=> int(91)
["post_author"]=> string(1) "1"
["post_date"]=> string(19) "2013-09-04 13:14:17"
["post_date_gmt"]=> string(19) "2013-09-04 13:14:17"
["post_content"]=> string(285) "Snowy Egret"
["post_title"]=> string(11) "Snowy Egret"
["post_excerpt"]=> string(0) ""
["post_status"]=> string(7) "publish"
["comment_status"]=> string(4) "open"
["ping_status"]=> string(4) "open"
["post_password"]=> string(0) ""
["post_name"]=> string(11) "snowy-egret"
["to_ping"]=> string(0) ""
["pinged"]=> string(0) ""
["post_modified"]=> string(19) "2013-09-06 08:36:01"
["post_modified_gmt"]=> string(19) "2013-09-06 08:36:01
["post_content_filtered"]=> string(0) ""
["post_parent"]=> int(0)
["guid"]=> string(44) "/trouble_focusing/?p=91"
["menu_order"]=> int(0)
["post_type"]=> string(4) "post"
["post_mime_type"]=> string(0) ""
["comment_count"]=> string(1) "0"
["filter"]=> string(3) "raw"
["format_content"]=> NULL
}