我有以下查询来从“myportfoliotype”帖子类型中获取所有图像,它工作正常。
但是,我希望在页面加载/刷新时拉入的所有图像都是随机的。
我遵循了一些教程,并提出了以下代码:
<?php
$query = new WP_Query( array( 'post_type' => 'myportfoliotype', 'posts_per_page' => -1, 'orderby' => 'rand' ) );
if( $query->have_posts() ){
while($query->have_posts()){
$query->the_post();
$do_not_duplicate = $post->ID;
$thumb_id = get_post_thumbnail_id( $post_id );
$image_query = new WP_Query( array('post__not_in' => array (MultiPostThumbnails::has_post_thumbnail('myportfoliotype', 'logo'), $thumb_id ), 'orderby' => 'rand' , 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'image', 'posts_per_page' => -1, 'post_parent' => get_the_ID() ) );
while( $image_query->have_posts() ) {
$image_query->the_post();
$do_not_duplicate = $post->ID;
//echo wp_get_attachment_image( get_the_ID() );
$image = wp_get_attachment_image_src(get_the_ID(), 'large');?>
<li> <a class="fancybox" rel="gallery1" href="<?php echo $image[0]; ?>"> <img src="<?php echo get_template_directory_uri(); ?>/js/timthumb.php?src=<?php echo $image[0]; ?>&w=137&h=137&f=2" alt="<?php the_title(); ?>" class="grey"/></a>
<img src="<?php echo get_template_directory_uri(); ?>/js/timthumb.php?src=<?php echo $image[0]; ?>&w=200&h=200" alt="<?php the_title(); ?>" class="color"/>
</li>
<?php
}
}
}
?>
我不太确定这是否正确?如前所述,它会拉入图像但不是随机的....
任何帮助或指导将不胜感激。
干杯,丹