2012-12-26 43 views
1

我已创建自定义幻灯片帖子类型。图像设置为每个新幻灯片帖子的精选图像。我想要在幻灯片模板中检索这些图像。这个幻灯片模板如何从自定义帖子类型检索精选图片?

HTML标记是:

<div class="wrapper"> 
<ul id="my-slider" class="my-slider"> 

<li> 
<a href="http://www.flickr.com/photos/photo/123456" target="_blank"><img src="images/1.jpg" alt="image1"/></a> 
<div class="my-description"> 
<h3>Image one</h3> 
</div> 
</li> 

<li> 
<a href="http://www.flickr.com/photos/photo/1234565" target="_blank"><img src="images/2.jpg" alt="image2"/></a> 
<div class="my-description"> 
<h3>Image two</h3> 
</div> 
</li> 


<li> 
<a href="http://www.flickr.com/photos/photo/12345655" target="_blank"><img src="images/3.jpg" alt="image3"/></a> 
<div class="my-description"> 
<h3>Image three</h3> 
</div> 
</li> 

<li> 
<a href="http://www.flickr.com/photos/photo/12345666" target="_blank"><img src="images/4.jpg" alt="image4"/></a> 
<div class="my-description"> 
<h3>Image four oner</h3> 
</div> 
</li> 
</ul> 
</div> 

此HTML提供了四个滑动图片为我硬编码it.How从WordPress的自定义后类型动态检索附加的图像得到同样的结果呢?

+0

你能解释一下你的意思是什么SRC **如何从WordPress的自定义后类型动态检索附加的图像** ? – samayo

+0

我的意思是我想从自定义文章类型中获取我的精选图片。一旦我有我的模板,我不想在模板中添加每个图像,如上所示。我想通过简单地创建具有特色图像的新幻灯片帖子来获取任意数量的图像。 – galexy

+0

你打算如何“发布”这些图像的数据?数据库驱动(3列)或写在一个文件作为字符串为ie? – Xfile

回答

2

我已经让所有的图像阵列从自定义后类型并将其存储在变量$ MYIMAGE实现这一点。 $ MYIMAGE [0]是img标签这就需要在循环赶上来获取所有图像

global $post; 
$args = array(
'post_type' =>'slideshow', 
'numberposts' => -1, 
'orderby' => 'menu_order'); 

$slider_posts = get_posts($args); ?> 
<?php if($slider_posts) { ?> 
<?php // start the loop 
foreach($slider_posts as $post) : setup_postdata($post); 
$myimage = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); 
3

为什么不简单地查询您的自定义帖子类型?举个例子:

<?php 
$args = array('post_type' => 'your_custom_post_type'); 
query_posts($args); 

// the Loop 
while (have_posts()) : the_post(); 
    //Do your stuff 

    //You can access your feature image like this: 
    the_post_thumbnail(); 
endwhile; 
2
Below is the example to retrive feature image. 

$args = array('post_type' => 'your_custom_post_type'); 
query_posts($args); 

// the Loop 
while (have_posts()) : the_post(); 

if (has_post_thumbnail()) { 

//Image size small,large or medium 
    the_post_thumbnail('thumbnail',imagesize);?> 


} 
?> 
endwhile; 
相关问题