如何通过WP_Query显示自定义帖子类型的图库(图像) [英] How to Display Custom Post Type's Gallery (images ) in Through WP_Query

查看:23
本文介绍了如何通过WP_Query显示自定义帖子类型的图库(图像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从自定义帖子类型图像库功能加载图像滑块图像.例如,假设我有一个名为 banner 的自定义帖子类型,我可以将图像加载到它的图库,并且我有一个这样的 HTML 代码:

<img src="assets/img/ban1r.jpg" alt=""><div class="carousel-caption">幻灯片 1

<div class="item active"><img src="assets/img/ban2r.jpg" alt=""><div class="carousel-caption">幻灯片 1

能否请您告诉我如何使用自定义 WP_Query 从自定义帖子中检索图像并将它们加载到滑块而不是 HTML 上方?

到目前为止,我已经做了类似的事情,但它没有显示任何图像!

 'banner');$loop = new WP_Query( $args );while ( $loop->have_posts() ) : $loop->the_post();$gallery = get_post_gallery_images($post);foreach( $gallery as $image ) {echo '

';echo '<img src="' . $image . '">';回声'</div>';}终了;?>

解决方案

我在 2 个月前尝试过类似的方法,对我来说效果很好.

全局$wpdb;$query = "select * from $wpdb->posts在哪里post_type = 'banner' 和post_status = '发布'";$results = $wpdb->get_results($query, ARRAY_A);foreach( $results 作为 $result ){echo '<div id="'.$result['ID'].'" class="listen">';echo get_the_post_thumbnail( $result['ID'], array(200, 200) );

';}

查看get_the_post_thumbnail

I am trying to load an Image Slider images from a Custom Post Type image Gallery Feature. For example let say I have an Custom Post Type called banner which I can load images to it's Gallery and I have an HTML code like this:

<div class="item active">
  <img src="assets/img/ban1r.jpg" alt="">
  <div class="carousel-caption">
    slide 1
  </div>
</div>

<div class="item active">
  <img src="assets/img/ban2r.jpg" alt="">
  <div class="carousel-caption">
    slide 1
  </div>
</div>

Can you please let me know how I can use the custom WP_Query to retrive the images from the custom post and load them into slider instead of above HTML?

So far I have done something like this but it is not displaying any image!

<?php
$args = array( 'post_type' => 'banner');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    $gallery = get_post_gallery_images($post);
foreach( $gallery as $image ) {
       echo '<div class="item active">';
       echo '<img src="' . $image . '">';
       echo '</div>';
    }
endwhile;
?>

解决方案

I tried something like this before 2 months ago, and working great for me.

global $wpdb;

$query = "select * from $wpdb->posts 
             where 
             post_type = 'banner' and 
             post_status = 'publish'";
$results = $wpdb->get_results($query, ARRAY_A);

foreach( $results as $result ){

    echo '<div id="'.$result['ID'].'" class="listen">';
    echo get_the_post_thumbnail( $result['ID'], array(200, 200) );
    </div>';

}

Take a look on get_the_post_thumbnail

这篇关于如何通过WP_Query显示自定义帖子类型的图库(图像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆