我有一个页面(不是文章)与n个子页面。 在主页面中,我需要显示最多3个子页面的标题,并为另一个页面插入分页。WordPress的自定义循环添加分页显示子页面
我该怎么做?
这是我现在简单的代码:
<?php
$parent_id = 14; //main page id
$pages = get_pages(array('sort_column' => 'menu_order', 'numberposts' => 3, 'child_of' => $parent_id));
foreach ($pages as $page) : ?>
<div class="item">
<div class="item-title">
<h2><a href="<?php echo get_permalink($page->ID); ?>"><?php echo $page->post_title; ?></a></h2>
</div>
</div>
<?php endforeach; ?>
感谢。
你几乎已经明白了。但是,为了对get_pages函数的结果进行微调,我建议您使用自定义查询来获取ID大于当前子页面的1个子页面,该子页面将成为“下一个链接”,而带ID的子页面少于当前将是'prev链接'。 – Sterex 2011-12-30 14:30:59