我有以下代码从我用来显示在存档页面中的帖子中提取自动生成的缩略图图像。该代码在我的本地服务器上运行良好,但一旦我将其上传到网络,它就无法正常工作。
- - 编辑 - - -
它现在显示的是每个帖子的相同缩略图,链接到输入的第一个帖子。任何想法为什么会这样?
<ul>
<?php query_posts('cat='.get_query_var('cat').'&order=ASC'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
//Get images attached to the post
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'order' => 'DESC',
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$img = wp_get_attachment_thumb_url( $attachment->ID );
break;
}
}
?>
<li>
<img src="<?php echo $img; ?>" alt="" />
<h2 class="small"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
</li>
<?php endwhile; ?>
<?php endif;?>
</ul>