【发布时间】:2013-02-23 08:02:56
【问题描述】:
我已经获取了以下代码来查询我在 Wordpress 中的帖子,并且所有工作都按预期工作。
我现在想为此添加分页。既然我知道它可以工作,我不想过多地更改代码,任何人都可以建议最好的方法来调整它以包含分页吗?
我希望它最多显示18 posts per page 并在其他页面上显示next 和prev links(如果存在)。此代码用于自定义类别模板,但我还在阅读设置下设置了一个静态页面设置,并且主要帖子的显示使用 home.php,我想使用相同或相似的循环代码来分页.任何帮助表示赞赏。代码如下:
<div id="Items">
<ul>
<?php
// Grid sorted alphabetically
if (is_category('categoryName'))
{
$args = array( 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC', 'category' => 41 );
$categoryNameposts = get_posts( $args );
}
foreach( $categoryNameposts as $post ) : setup_postdata($post);
?>
<li><?php get_template_part( 'content', get_post_format() ); ?></li>
<?php endforeach; ?>
</ul>
</div><!-- #ItemsEnd -->
【问题讨论】:
标签: foreach pagination wordpress