如何在wordpress中以分页形式显示类别循环
我想显示类别名称和类别缩略图,它需要显示每页5个类别和其他相应页面中的其他类别。请任何人对此有解决办法 代码如下:如何在wordpress中以分页形式显示类别循环,wordpress,pagination,categories,Wordpress,Pagination,Categories,我想显示类别名称和类别缩略图,它需要显示每页5个类别和其他相应页面中的其他类别。请任何人对此有解决办法 代码如下: <?php $posts_per_page = 4; $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $offset = ( $paged - 1 ); global $paged; $curpage = $paged ? $paged : 1; $args = array( 'c
<?php
$posts_per_page = 4;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$offset = ( $paged - 1 );
global $paged;
$curpage = $paged ? $paged : 1;
$args = array(
'child_of' => 4,
'order_by' => 'name',
'paged' => $paged
);
$categories = get_categories( $args );
foreach($categories as $category) {
echo '' . $category->name.'';
if(has_category_thumbnail($category->cat_ID)) {
the_category_thumbnail($category->cat_ID);
}
}
echo '
<div id="wp_pagination">
<a class="previous page button" href="'.get_pagenum_link(($curpage-1 > 0 ? $curpage-1 : 1)).'">‹</a>';
for($i=1;$i<=$categories->max_num_pages;$i++)
echo '<a class="'.($i == $curpage ? 'active ' : '').'page button" href="'.get_pagenum_link($i).'">'.$i.'</a>';
echo '<a class="next page button" href="'.get_pagenum_link(($curpage+1 <= $categories->max_num_pages ? $curpage+1 : $categories->max_num_pages)).'">›</a>
</div>
';
我终于找到了上述问题的解决方案。我希望它能对其他有同样问题的人有所帮助
请尝试以下代码:
<?php
$args = array(
'child_of' => 4,
'orderby' =>'date',
'order' =>'ASC'
);
$categories = get_categories($args);
$numOfItems = 4;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$to = $page * $numOfItems ;
$current = $to - $numOfItems;
$total = sizeof($categories);
?>
<div id="ns-main">
<?php
for ($i=$current; $i<$to; ++$i) {
$category = $categories[$i];
?>
<div class="ns-wrap">
<?php
if ($category->name) {
if(has_category_thumbnail($category->cat_ID)) {
the_category_thumbnail($category->cat_ID);
}
echo '' . $category->name.'';
}
?>
</div>
<?php
}
?>
</div>
<div id="wp_pagination">
<?php
unset($category);
echo paginate_links( array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => ceil($total / $numOfItems),
'current' => $page
));
?>
</div>
那么,你想对你的类别进行分页吗?是的,我想以分页的形式显示类别。你实际上做了什么自我检查问题我添加了我的代码片段。