Get current index position in loop in WordPress
获取当前元素的系列,只需要 $wp_query->current_post
while (have_posts()) : the_post();
// Some basic wordpress template tags
the_title();
the_content();
// Echo the current index position of the loop (0,1,2,3..etc)
echo $wp_query->current_post;
endwhile;
或者还有种原始的方法:
$key = "";
while (have_posts()) : the_post();
// Some basic wordpress template tags
the_title();
the_content();
echo $key;
$key++
endwhile;