我使用WP_Term_Query
创建了一个类别列表页面,但我需要对此页面进行分页的分页。
<?php
if (is_category())
$current_cat = get_query_var('cat');
$arg = array(
'taxonomy'=> 'category',
'child_of'=> $current_cat,
'number' => 2,
);
$term_query = new WP_Term_Query($arg);
?>
<div class="wb-subcategories">
<?php
foreach ($term_query->terms as $subcat):
$subcat_link = get_category_link( $subcat->term_id );
?>
<div class="wb-subcat">
<a href="<?php echo esc_url( $subcat_link ); ?>">
<div class="subcat-img">
<div class="overlay"></div>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/happy-woman.jpg" alt="">
</div>
<div class="subcat-title">
<h3><?php echo $subcat->name; ?></h3>
<span>( <?php echo $subcat->count ?> )</span>
</div>
</a>
</div>
<?php
endforeach;
?>
</div>
我已经使用paginate_links();
功能,但它无效。它显示分页编号但分页编号链接不起作用。
$big = 999999999; // need an unlikely integer
$max_num_pages = ceil($term_query->query_vars['total_category']/ $term_query->query_vars['number']);
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '%#%',
'current' => max(1, get_query_var('paged')),
'total' => $max_num_pages,
'offset' => $offset
));
我只需要对类别列表进行分页,而不是分类。