【发布时间】:2014-05-21 02:09:36
【问题描述】:
我有一个与自定义分类(支持)相关的自定义帖子类型(问题)
在 my-theme/taxonomy.php 我有这个代码:
<?php
$taxonomy = get_queried_object()->taxonomy;
if ($taxonomy == 'support')
{
get_template_part('template/support/categories');
exit;
}
wp_safe_redirect(site_url('/'));
exit;
?>
意味着我针对“支持”分类法的特定模板文件。
在我的分类模板文件中,我进行了自定义查询:
<?php $current_category = get_term_by('id', get_queried_object()->term_id, 'support'); ?>
<?php $questions = new WP_Query(array(
'post_type' => array('question'),
'post_status' => 'publish',
'posts_per_page' => 5,
'posts_per_archive_page' => 5,
'paged' => ((get_query_var('page')) ? get_query_var('page') : 1),
'nopaging' => false,
'tax_query' => array(
array(
'taxonomy' => 'support',
'terms' => array($current_category->term_id)
)
),
'orderby' => 'menu_order',
'order' => 'ASC'
)); ?>
<?php if ($questions->have_posts()): ?>
<ul class="list normalize">
<?php while ($questions->have_posts()) : $questions->the_post(); ?>
<li>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<div class="nav-previous">
<?php next_posts_link( __('Previous', 'my-theme'); ?>
</div>
<div class="nav-next">
<?php previous_posts_link( __('Next', 'my-theme'); ?>
</div>
<?php wp_reset_postdata(); ?>
我有大约 11 个帖子,第 1 页显示了前 5 个帖子,但问题是没有显示分页。
有什么想法吗? 谢谢
【问题讨论】:
标签: wordpress pagination custom-post-type