admin管理员组文章数量:1125586
I have this code to loop coupon codes in store page.
Current coupons open in same page of store page.
I want move the current coupon to top of loop.
<?php
while ( have_posts() ) {
the_post();
wpcoupon_setup_coupon( get_post( get_the_ID() ) );
get_template_part( 'loop/loop-coupon', $loop_tpl );
}
?>
I have this code to loop coupon codes in store page.
Current coupons open in same page of store page.
I want move the current coupon to top of loop.
<?php
while ( have_posts() ) {
the_post();
wpcoupon_setup_coupon( get_post( get_the_ID() ) );
get_template_part( 'loop/loop-coupon', $loop_tpl );
}
?>
Share
Improve this question
edited Mar 7, 2024 at 14:40
Tony Djukic
2,2594 gold badges18 silver badges33 bronze badges
asked Mar 6, 2024 at 23:52
user3418508user3418508
133 bronze badges
3
- 2 What makes a coupon the 'current' coupon? – Jacob Peattie Commented Mar 7, 2024 at 1:27
- Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Mar 7, 2024 at 14:40
- this is code for id of the coupon, <?php echo wpcoupon_coupon()->ID; ?> I dont know the code for current coupon because the coupon open in same store. with pop up – user3418508 Commented Mar 9, 2024 at 0:19
1 Answer
Reset to default 0To move the current coupon to the top of the loop, you can use an approach that involves storing the current coupon data temporarily and then outputting it separately before looping through the rest of the coupons.
Replace /* Your condition to determine current coupon */
with the condition that identifies the current coupon within your loop
<?php
$current_coupon = null; // Initialize variable to store current coupon
// First, find and store the current coupon
while ( have_posts() ) {
the_post();
$post_id = get_the_ID();
wpcoupon_setup_coupon( get_post( $post_id ) );
// Check if this is the current coupon
if ( /* Your condition to determine current coupon */ ) {
$current_coupon = [
'post_id' => $post_id,
// Store any other relevant data about the current coupon
];
continue; // Skip outputting the current coupon for now
}
// Output other coupons
get_template_part( 'loop/loop-coupon', $loop_tpl );
}
// Output the current coupon separately at the top
if ($current_coupon) {
wpcoupon_setup_coupon( get_post( $current_coupon['post_id'] ) );
get_template_part( 'loop/loop-coupon', $loop_tpl );
}
?>
本文标签: phpWordPress move current to top in the loop
版权声明:本文标题:php - WordPress move current to top in the loop 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736625505a1945665.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论