Php 在Wordpress中显示帖子缩略图仅显示第一个缩略图

Php 在Wordpress中显示帖子缩略图仅显示第一个缩略图,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我想在侧边栏上显示最新的文章标题和缩略图。 到目前为止,我得到的职位标题,只有一个缩略图复制。 您可以看到结果。(仅显示第一个/最早的后期图像) 这是我的密码: $rps = wp_get_recent_posts($params); foreach($rps as $rp) : $args = array( 'post_type' => 'attachment', 'numberposts' => 1,

我想在侧边栏上显示最新的文章标题和缩略图。 到目前为止,我得到的职位标题,只有一个缩略图复制。 您可以看到结果。(仅显示第一个/最早的后期图像)

这是我的密码:

$rps = wp_get_recent_posts($params);
foreach($rps as $rp) :
    $args = array(
            'post_type' => 'attachment',
            'numberposts' => 1,
            'post_status' => null,
            'post_parent' => $post->ID
             );

    $attachment = current(get_posts( $args ));
?>
<a href="<?php echo get_permalink($rp['ID']);?>"><?php echo $rp['post_title'];?><?php echo wp_get_attachment_image( $attachment->ID, 'thumbnail' );?></a>
<?php endforeach; ?>
$rps=wp\u get\u recent\u posts($params);
foreach($rps为$rp):
$args=数组(
“post_类型”=>“附件”,
“numberposts”=>1,
“post_状态”=>null,
“post\u parent”=>$post->ID
);
$attachment=当前(get_posts($args));
?>
感谢您提供的任何提示/帮助。

运行2

一个输出第一个职位。第二个输出除第一个之外的所有其他内容

<?php $args = array( 'post_type' => 'attachment', 'posts_per_page' => 1, 'post_parent' => $post->ID);  
$first = new WP_Query( $args ); 
while ( $first->have_posts() ) : $first->the_post(); ?>
<a href="<?php echo get_permalink();?>"><?php the_title();?><?php echo wp_get_attachment_image( $first->ID, 'thumbnail' );?></a>
<?php endwhile; wp_reset_postdata(); ?>
<?php $args2 = array( 'post_type' => 'attachment', 'posts_per_page' => 1, 'post_parent' => $post->ID, 'offset' => 1);  
$rest = new WP_Query( $args2 );
while ( $rest->have_posts() ) : $rest->the_post(); ?>
<a href="<?php echo get_permalink();?>"><?php the_title();?><?php echo wp_get_attachment_image( $rest->ID, 'thumbnail' );?></a>
 <?php endwhile; wp_reset_postdata(); ?>

'post\u parent'=>$post->ID
替换为
'post\u parent'=>$rp['ID']
。就这样。 您正在做的是,您正在为所有帖子传递当前帖子的ID(以$args为单位)