我制作了一个Wordpress主题,有页面和帖子。文章的循环向我展示了一个简短的帖子和一个继续阅读链接。我喜欢这个,但我怎样才能使主题显示在帖子简介的循环图像(S)附在文章开头,如果有的话。
谢谢!
发布于 2011-04-08 22:42:31
您可以通过以下方式获得附加的图像:
$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');发布于 2011-04-09 13:19:35
这是为了得到所有的注意图像与你的帖子。
$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');
}
}发布于 2011-04-08 22:13:21
您应该在循环中添加:
<?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"对应于您想要显示的大小。
https://stackoverflow.com/questions/5601218
复制相似问题