<?php while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
这两行,是 WP 中的 while 循环。其中,while 语句通过测试 have_posts() 决定是否调用 the_post() 函数。如果测试 have_posts() 返回 true,则调用 the_post() 函数,初始化与博文相关的内置变量。
在 while 循环内部,首先要注意通过 div、h2、span 这三个元素定义的嵌套语义结构,以及相应元素的 class 和 id 属性(其中只为 class 为 post 的 div 元素定义了一个 id 属性--post-<?php the_ID() ?>)。这是将来使用 CSS 控制外观的关键所在。在这个 div 元素中,为显示博文的相关信息,分别调用了以下 WP 函数: