我需要为WordPress自定义帖子类型创建手动分页;情况解释如下。
自定义帖子类型为"调查">
我希望每个调查问题都显示在单个页面上,然后单击下一步按钮后,应重新加载页面并显示下一个问题,因此调查的结构应该像
起始页: http://www.example.com/survey-title/
问题 1: http://www.example.com/survey-title/q/1/
问题 2: http://www.example.com/survey-title/q/2/
问题3:http://www.example.com/survey-title/q/3尾页: http://www.example.com/survey-title/result/
根据通过的问题编号(q(,我可以检索所需的问题。
有哪些可能的选项(在不可能修改核心 wp 结构的情况下(来实现这一点?
附言它旨在成为我们通过使用标签将帖子/页面内容拆分为多个分页页面而获得的类似功能<!--more-->
。
任何帮助都非常感谢。
您基本上需要创建一个页面来循环使用自定义类型"调查"的帖子,每页给它一些帖子,并添加一个小技巧以使分页工作。
听起来很简单?以下是代码翻译:
$args = array(
'post_type' => 'survey', //your post type
'posts_per_page' => 1 // number of posts you want to see per page, in your case, 1
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content()
echo '</div>';
endwhile;
<!-- Add the pagination functions here. -->
<div class="nav-previous alignleft"><?php next_posts_link( 'Next Page' ); ?></div>
您是在每页上发布数据还是仅在最后保存到 POST? 如果是最后一种情况,这是行不通的。