我试图有五个广告位置,每个位置都从相同的自定义帖子类型中拉帖子,但也随机加载。我下面的代码唯一的问题是,它有时会重复显示的帖子。有没有办法让所有5个广告都显示一个随机的广告帖子而不重复?
下面是其中一条横幅:
<div class="advertisement">
<?php query_posts(\'post_type=advertisement_posts&offset=1&orderby=rand&showposts=1\');?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $advert_url = get_post_meta($post->ID, \'rba_advert_url\'); ?>
<?php $thumbnail_id = get_the_post_thumbnail($post->ID);
preg_match (\'/src="(.*)" class/\',$thumbnail_id,$link);
if(!empty($thumbnail_id)) {
$image_path = thumbGen($link[1],234,116,"crop=1&halign=center&valign=center&return=1");
$image_all = get_bloginfo(\'url\').$image_path;
$my_image = array_values(getimagesize($image_all));
list($width, $height, $type, $attr) = $my_image;
}
?>
<?php if(has_post_thumbnail()) : ?>
<a href="<?php echo $advert_url[0]; ?>" target="_blank">
<img src="<?php echo $image_path; ?>" alt="<?php the_title(); ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>"/>
</a>
<?php endif; ?>
<?php endwhile; ?>
<?php endif;?>
<?php wp_reset_query(); ?>
</div>
有什么想法吗?