因此,我试图将内容分为几页。我知道如何使用paginate_links( $args );
将帖子划分为页面,但是我不知道如何在wp_query
循环之外添加帖子
foreach($categories as $cat_id ){
$query = new WP_QUERY(array(
'post_type' => 'post',
'category__in' => $cat_id));
while($query->have_posts()){
$query->the_post();
//content
}
// Posts from different categories should be on different pages
}
答案 0 :(得分:0)
尝试以下代码:
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$dataQuery = new WP_Query(
array(
'post_type'=>'post', // your post type name
'posts_per_page' => 5, // post per page
'paged' => $paged,
)
);
if($dataQuery->have_posts()) :
while($dataQuery->have_posts()) : $dataQuery->the_post();
// Your code
endwhile;
$totalPage = $data->max_num_pages;
if ( $total_pages > 1 ){
$currentPage = max( 1, get_query_var('paged') );
echo paginate_links(
array(
'base' => get_pagenum_link( 1 ) . '%_%',
'format' => '/page/%#%',
'current' => $currentPage,
'total' => $totalPage,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
)
);
}
?>
<?php else :?>
<h3>No pagination found </h3>
<?php endif; ?>
<?php wp_reset_postdata();?>