关键函数:
have_posts():
have_posts() 默认是一个全局函数;
have_posts函数被调用时实际上是调用全局变量$wp_query->have_posts()成员函数,来简单检查一个全局数组(array)变量$posts的一个循环计数器,以确认是否还有post,如果有返回true(1),如果没有返回false(0)。
the_post()
the_post()函数则调用$wp_query->the_post()成员函数前移循环计数器,并且创建一个全局变量$post(不是$posts),把当前的post的所有信息都填进这个$post变量中,以备接下来使用。比如:
the_ID()
post_class()
get_the_title()
the_content()
Template Tags(在循环内使用)
简单的使用可以通过函数来直接执行,如the_content()直接显式post的内容,the_title()显式帖子的标题,the_time()显示帖子的时间等WORDPRESS的Template Tags。比如:
<?php if (have_posts()) :
while (have_posts()) : the_post(); ?>
当找到文章时返回此语句
<?php endwhile; else : ?>
当没有找到文章时,返回此语句
<?php endif; ?>