Wordpress - 循环播放到的图像

时间:2011-04-08 22:00:16

标签: wordpress

我制作了一个WordPress主题,包括页面和帖子。 帖子循环向我展示了一个简短的帖子简介和一个继续阅读链接。 我喜欢这个,但是如果有的话,如何在开头的帖子附加到帖子的简短的主题节目中显示主题节目,如果有的话。

谢谢!

3 个答案:

答案 0 :(得分:3)

您可以使用以下方式获取附加图像:

$args = array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'numberposts' => 1,
    'orderby' => 'menu_order',
    'order' => 'ASC',
    'post_parent' => $post->ID
);
$images = get_posts($args);

并显示如下:

echo wp_get_attachment_image($images[0]->ID, $size='attached-image');

答案 1 :(得分:2)

这是用你的帖子获取所有附件图像。

   $args = array( 
                 'post_type' => 'attachment', 
                 'post_mime_type' => 'image',
                 'post_status' => null, 
                 'post_parent' => $post->ID 
           );

   $attachments = get_posts( $args );

   if ($attachments) {
      foreach ( $attachments as $post ) {
         $img = wp_get_attachment_image_src($post->ID, 'medium'); 
         $fullsize = wp_get_attachment_image_src($post->ID, 'full');
      }
   }

答案 2 :(得分:0)

你应该加入你的循环:

<?php
   if(has_post_thumbnail()) {
      $theimage = wp_get_attachment_image_src( get_post_thumbnail_id ( $post->ID ), 'thumbnail' );
}
?>
<img class="img_class" src="<?php echo $theimage[0]; ?>" />

"thumbnail"对应于您要显示的尺寸。

请记住,还有一个WordPress specific site in StackExchange

相关问题