dtgr3392 2012-12-26 11:44
浏览 25
已采纳

如何从自定义帖子类型中检索特色图片?

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?

  • 写回答

3条回答 默认 最新

  • dongzhan7253 2012-12-27 12:50
    关注

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)