循环时,WordPress查找当前id并获取下一个id


While loop, WordPress find current id and get Next id

使用while循环,

<?php
$current_id = get_the_ID();
echo $current_id;
$args=array(
  'portfolio-tag' => 'corporate',
  'showposts'=>0,
  'orderby'=>'post_date',
  'order'=>'ASC',
  'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
  while ($my_query->have_posts()) : $my_query->the_post();
      echo get_the_ID();
  endwhile;
} 
wp_reset_query();
?>

在我的WordPress细节上它看起来像。

308
368
420
980
1147
1157

这些是公文包项目id。如果我是当前的详细信息页面id,我试图实现的是368使用这个。

get_the_ID();

有人能告诉我如何在while循环中找到当前id吗?在这种情况下,368在第二个数字上。所以我需要420 id,因为420在368之后。

这就是get_next_post()的用途:

if( $my_query->have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post();
    the_ID();  // display the current post ID
    $next_post = get_next_post();
    echo !empty( $next_post ) ? 'Next Post ID: ' . $next_post->ID : 'No next post';
endwhile; endif;