我們在開發(fā)WordPress主題的過程中,是不是會遇到調(diào)用文章列表和文章內(nèi)容的功能?這里就需要用到循環(huán)調(diào)用功能。這里我們將常見的文章列表和文章內(nèi)容調(diào)用的循環(huán)方法記錄。
1、文章列表調(diào)用
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title( '<h2>', '</h2>' ); the_post_thumbnail(); the_excerpt(); endwhile; else: _e( '抱歉,未找到您需要的文章。', 'textdomain' ); endif; ?>
2、文章內(nèi)容調(diào)用
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title( '<h1>', '</h1>' ); the_content(); endwhile; else: _e( '抱歉,未找到您需要的文章。', 'textdomain' ); endif; ?>
這里是常見的沒有特殊循環(huán)判斷的調(diào)用。如果我們希望指定分類或者多循環(huán)的,還需要嵌套其他的。具體我們以后遇到再補充。
評論