文章描述:
wordpress网站的首页调取所有文章进行分页显示
1、循环
调用所有文章用到了if判断语句和while循环语句
2、函数
have_posts():这个函数被调用时,会调用全局变量$wp_query->have_posts()成员函数,查看全局数组变量$posts的一个循环计数器,检查还有没有post文章,如果有就返回真,否则返回假。
the_post():这个函数调用$wp_query->the_post()成员函数前移循环计数器,并且创建一个全局变量$post,把当前的post文章的所有信息都赋值给这个$post变量中,以备接下来使用。
3、分页
使用默认的分页函数来进行分页
<ul>
<?php
if(have_posts()):
while(have_posts()):
the_post();
?>
<li><a href=\"<?php the_permalink()?>\"><?php the_title(); ?></a><i><?php echo get_the_time(\"Y-m-d\")?></i></li>
<?php
endwhile;
?>
<?php posts_nav_link();?>
<?php
endif;
?>
</ul>
THE END
请登录后查看评论内容