WordPress主题开发:循环代码

have_posts() 有没有文章信息

if...else

<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
<!-- 在这里调用数据 -->
<?php endwhile; ?>
<?php endif; ?>

 

if....else.if ...else

<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
<!-- 在这里调用数据 -->
<?php endwhile; ?>
<?php else: ?>
<!--  如果没有数据则显示什么  -->
<?php endif; ?>

 

注意:主循环的内容会自动匹配调用的页面类型,如主页下循环的是文章列表内容,而在single.php中调用的是当前id的页面内容。

 

参考文档:

http://codex.wordpress.org/The_Loop

http://codex.wordpress.org/The_Loop_in_Action

更多循环写法参考代码:

http://download.csdn.net/detail/roro5119/9744732

 

posted @ 2017-01-25 23:39  tinyphp  Views(933)  Comments(0Edit  收藏  举报