【发布时间】:2013-11-27 07:56:52
【问题描述】:
在category.php,我想获取该类别的帖子列表。
我找到了两种方法:使用get_posts($args) 和The Loop。
get_posts()方式
$args = array (
"category" => ID );
$posts = get_posts($args);
// then use foreach to loop the $posts
循环方式
<?php if (have_posts() ): ?>
<?php while (have_posts() ): the_post(); ?>
...
<?php endwhile; ?>
<?php endif; ?>
那么哪个更高效?
根据我在搜索中的发现,get_posts() 用于自定义模板,而The Loop 在遵循 Wordpress 命名约定的模板中使用。
我更喜欢 get_posts(),但如果与 The Loop 相比开销很大,我应该重新考虑一下。
【问题讨论】:
标签: php wordpress loops wordpress-theming