我做了一个WordPress的主题,页和帖子。 帖子循环显示我的简短帖子和继续阅读链接。 我喜欢这个,但是我怎样才能在开始时发布的循环图像(s)的帖子简要中做主题展示,如果有的话。WordPress的 - 循环与张贴的图像
谢谢!
我做了一个WordPress的主题,页和帖子。 帖子循环显示我的简短帖子和继续阅读链接。 我喜欢这个,但是我怎样才能在开始时发布的循环图像(s)的帖子简要中做主题展示,如果有的话。WordPress的 - 循环与张贴的图像
谢谢!
您应该添加在你的循环:
<?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"
对应要显示的大小。
您可以通过使用让您的图片附件:
$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');
这对于让所有attachement图片与您的帖子。
$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:25:41
那么,你问这样的事情? [获取第一张图片](http://www.wprecipes.com/how-to-get-the-first-image-from-the-post-and-display-it) – konus 2011-04-08 22:37:12
如果你不使用wordpress的图片管理员添加图片发布后,您将不得不使用该解决方案。但是,如果你真的使用wordpress的图片管理器,你可能需要使用answeres我的解决方案。因为,在邮政上做正则表达式并不是真正聪明的解决方案。假设你对你的帖子有兴趣并且首先出现,你最终会显示它。 – ariefbayu 2011-04-08 22:47:04