但具体来说,我需要从帖子中检索某些数据,并在优惠券列表中首先显示一个类别的帖子数据(首选项),然后在列表中显示其他类别的帖子数据。
我的意思是说,假设前6张优惠券是第一优先选择,那么它将首先显示,然后显示其他优惠券。然后进行分页。因此,正如@Swopnil Dangol所建议的,我尝试将这两个循环分别用于(一个类别和其他类别)。
但问题是,即使我单击了第二个页面,它也显示了第一个页面的数据,而不是其余的数据。Thanx提前。我试图通过互联网找到答案,但没有成功,请帮忙。
<?php
$args = array();
$args[\'post_type\'] = \'coupons\';
$args[\'cat\'] = 20;
$query1 = new WP_Query($args);
while($query1->have_posts() ) : $query1->the_post();
$thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
$discount = get_post_meta($post->ID, \'_single_discount\', true);
$date = get_post_meta($post->ID, \'_single_date\', true);
$code = get_post_meta($post->ID, \'_single_code\', true);
$url = get_post_meta($post->ID, \'_single_url\', true);
$daysleft = round( ($date-time()) / 24 / 60 / 60);
?>
<div class="coupon">
<?php if($thumb != \'\') { ?>
<div class="coupon-top">
<figure>
<a href="<?php the_permalink();?>"><img src="<?php echo aq_resize($thumb, 300, 200, true); ?>" alt="<?php the_title();?>"></a>
</figure>
<div class="coupon-title">
<a href="<?php the_permalink();?>"><?php truncate_title(15);?></a>
</div>
</div>
<?php } ?>
<div class="coupon-bottom">
<div class="coupon-offer">
<?php echo substr($discount, 0, 15);?>
</div>
<div class="coupon-date">
<?php
if($date == \'\')_e(\'Хүчинтэй\', \'Couponize\');
else if($daysleft <= 0) _e(\'Дууссан\', \'Couponize\');
else echo sprintf( _n(\'%d day left.\', \'%d Хоног Үлдсэн.\', $daysleft, \'Couponize\'), $daysleft );
?>
</div>
</div>
</div>
<?php endwhile; wp_reset_postdata();?>
<?php
$args = array( \'category__not_in\' => array(20));
$args[\'post_type\'] = \'coupons\';
$query2 = new WP_Query($args);
while($query2->have_posts() ) : $query2->the_post();
$thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
$discount = get_post_meta($post->ID, \'_single_discount\', true);
$date = get_post_meta($post->ID, \'_single_date\', true);
$code = get_post_meta($post->ID, \'_single_code\', true);
$url = get_post_meta($post->ID, \'_single_url\', true);
$daysleft = round( ($date-time()) / 24 / 60 / 60);
?>
<div class="coupon">
<?php if($thumb != \'\') { ?>
<div class="coupon-top">
<figure>
<a href="<?php the_permalink();?>"><img src="<?php echo aq_resize($thumb, 300, 200, true); ?>" alt="<?php the_title();?>"></a>
</figure>
<div class="coupon-title">
<a href="<?php the_permalink();?>"><?php truncate_title(15);?></a>
</div>
</div>
<?php } ?>
<div class="coupon-bottom">
<div class="coupon-offer">
<?php echo substr($discount, 0, 15);?>
</div>
<div class="coupon-date">
<?php
if($date == \'\')_e(\'Хүчинтэй\', \'Couponize\');
else if($daysleft <= 0) _e(\'Дууссан\', \'Couponize\');
else echo sprintf( _n(\'%d day left.\', \'%d Хоног Үлдсэн.\', $daysleft, \'Couponize\'), $daysleft );
?>
</div>
</div>
</div>
<?php endwhile; wp_reset_postdata();?>