試試這個工作代碼
把這個功能您的活動主題的functions.php文件
function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 2;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => True,
'prev_text' => __('<i class="fa fa-angle-double-left"></i>'),
'next_text' => __('<i class="fa fa-angle-double-right"></i>'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<div class='col-md-12'><nav class='custom-pagination pagination'>";
echo $paginate_links;
echo "</nav></div>";
}
}
,這裏是你的修改後的代碼爲分頁
工作
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$all_active_tasks = get_posts(array(
'posts_per_page' => -1,
'paged' => $paged,
'offset' => 0,
'post_status' => 'publish',
'author' => '1',
'post_type' => 'post'
)
);
foreach($all_active_tasks as $post) :
$category = get_the_category();
setup_postdata($post);
?>
<div class="the-post">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php echo $category[0]->cat_name; ?></p>
</div>
<?php endforeach; ?>
<?php if (function_exists(custom_pagination)) {
custom_pagination(count($all_active_tasks),"",$paged);
}?>
<?php wp_reset_postdata(); ?>
這導致我最終得到它的工作。謝謝! – user3256143
不客氣:) – pgk