2012-12-26 42 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; 
相關問題