我们在开发WordPress主题的过程中,是不是会遇到调用文章列表和文章内容的功能?这里就需要用到循环调用功能。这里我们将常见的文章列表和文章内容调用的循环方法记录。
1、文章列表调用
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title( '<h2>', '</h2>' );
the_post_thumbnail();
the_excerpt();
endwhile;
else:
_e( '抱歉,未找到您需要的文章。', 'textdomain' );
endif;
?>
2、文章内容调用
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title( '<h1>', '</h1>' );
the_content();
endwhile;
else:
_e( '抱歉,未找到您需要的文章。', 'textdomain' );
endif;
?>
这里是常见的没有特殊循环判断的调用。如果我们希望指定分类或者多循环的,还需要嵌套其他的。具体我们以后遇到再补充。


评论