如何从自定义帖子类型中检索特色图片?
I have created Custom slideshow post type.Images set as featured images for each new slide post. I want to retrieve these image in slideshow template.
HTML markup for this slide template is:
<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>
This HTML gives four slide images as I hard-coded it.How to retrieve attached image dynamically from wordpress custom post type to get the same result?
我创建了自定义幻灯片后期类型。图像设置为每个新幻灯片的精选图像。 我想在幻灯片模板中检索这些图像。 p>
此幻灯片模板的HTML标记为: p>
&lt; div class =“wrapper”&gt;
&lt; ul id =“ my-slider“class =”my-slider“&gt;
&lt; li&gt;
&lt; a href =”http://www.flickr.com/photos/photo/123456"target =“_ blank”&gt; &lt; img src =“images / 1.jpg”alt =“image1”/&gt;&lt; / a&gt;
&lt; div class =“my-description”&gt;
&lt; h3&gt;图片一&lt; / h3&gt; \ n&lt; / div&gt;
&lt; / li&gt;
&lt; li&gt;
&lt; a href =“http://www.flickr.com/photos/photo/1234565”target =“_ blank”&gt;&lt; img src =“images / 2.jpg”alt =“image2”/&gt;&lt; / a&gt;
&lt; div class =“my-description”&gt;
&lt; h3&gt;图片二&lt; / h3&gt;
&lt; / div&gt;
&lt; / li&gt;
&lt; li&gt;
&lt; a href =“http://www.flickr.com/photos/photo/12345655”target =“_ blank”&gt;&lt; img src =“images / 3.jpg”alt =“image3”/&gt;&lt; / a&gt;
&lt; div class =“my-description”&gt;
&lt; h3&gt;图片三&lt; / h3&gt;
&lt; / div&gt;
&lt; / li&gt;
&lt; li&gt;
&lt; a href =“http://www.flickr.com/photos/photo/12345666”target =“_ blank”&gt;&lt; img src =“images / 4.jpg”alt =“image4”/&gt ;&lt; / a&gt;
&lt; div class =“my-description”&gt;
&lt; h3&gt;图片四个oner&lt; / h3&gt;
&lt; / div&gt;
&lt; / li&gt;
&lt; / ul&gt; \ n&lt; / div&gt;
code> pre>
这个HTML提供了四张幻灯片图像,因为我对其进行了硬编码。如何从wordpress自定义帖子类型中动态检索附加图像以获得相同的效果 结果? p>
div>
I have implemented this by getting array of all images from custom post type and storing it in variable $myimage. $myimage[0] is the src for img tag which need to catch in loop to get all images
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');
Why not simply query for your custom post type? An example:
<?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;
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;