页面模板上自定义帖子类型的分页
问题描述:
你好我正在尝试添加分页到我用来显示自定义帖子类型的页面模板。我环顾了几个小时,但我还没有遇到明确的指示要遵循。页面模板上自定义帖子类型的分页
以下是我的页面模板php文件中的所有代码。如果有人能指出我正确的方向,将不胜感激。
我将不胜感激如何添加代码
<?php
/*
Template Name: Testimonials
*/
?>
<?php get_header(); ?>
<div class="container_12">
<div id="content" class="grid_8">
<h1><?php the_title(); ?></h1>
<div id="testimonials">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $testimonials = new WP_Query(array('post_type' => 'testimonial', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => '2', 'paged' => $paged)); ?>
<?php if (have_posts()) : ?>
<ul>
<?php while ($testimonials->have_posts()) : $testimonials->the_post(); ?>
<li>
<?php the_content(); ?>
<span><?php the_title(); ?></span>
</li>
<?php endwhile; ?>
</ul>
<?php else : ?>
<p><?php _e('No entry found.'); ?></p>
<?php endif; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
</div><!-- #testimonials -->
</div><!-- #content -->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
我可以直接链接推荐/页/ 2 /访问第2页任何帮助。但在第1页上,导航没有出现。
第1页:
第2页:
答
你应该WP查询后重置后的数据,我想。
检查StackExchange人回答这个 https://wordpress.stackexchange.com/questions/89191/using-query-posts-inside-single-php-loop
好运
答
尝试使用query_posts()
代替,看看是否能解决问题。
您是否向社区提供了有关此功能的反馈意见? – 2013-04-30 04:32:37