为WordPress自定义帖子类型创建手动分页

时间:2014-12-07 09:01:50

标签: php wordpress pagination

我需要为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结构)来实现这一目标?

P.S。它的目的是通过使用<!--more-->标记将帖子/页面内容拆分为多个分页页面而获得的类似功能。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您基本上需要创建一个页面,使用自定义类型“调查”来循环您的帖子,为每个页面添加一些帖子,并添加一个小技巧以使分页工作。

听起来很简单?这里翻译成代码:

$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?如果这是最后一种情况,那就不行了。