我已經創建了一個帶有數字分頁的自定義分類頁面模板,但問題是我無法查看帶有文章的第3頁。我的自定義分類頁面上的數字分頁
這裏是我的代碼,我在Function.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' => __('Previous'),
'next_text' => __('Next'),
'type' => 'plain',
'add_args' => False,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='custom-pagination'>";
echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
}
我在品類5.php添加什麼
<?php
/**
* Template Name: Custom Page
* The custom page template file
*/
get_header(); ?>
<div class="container">
<?php
\t $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
\t $custom_args = array('post_type' => 'post', 'posts_per_page' => 2, 'paged' => $paged);
\t $custom_query = new WP_Query($custom_args); ?>
\t
\t \t <?php if ($custom_query->have_posts()) : ?>
\t \t <!-- the loop -->
\t \t <?php while ($custom_query->have_posts()) : $custom_query->the_post(); ?>
\t \t \t <article class="loop">
\t \t \t \t <h3><?php the_title(); ?></h3>
\t \t <div class="content">
\t \t \t \t \t <?php the_excerpt(); ?>
\t \t \t \t </div>
\t \t \t </article>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php
if (function_exists(custom_pagination)) {
custom_pagination($custom_query->max_num_pages,"",$paged);
}
?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
<?php get_footer(); ?>
我的CSS
.custom-pagination span,
.custom-pagination a {
display: inline-block;
padding: 2px 10px;
}
.custom-pagination a {
background-color: #ebebeb;
color: #ff3c50;
}
.custom-pagination a:hover {
background-color: #ff3c50;
color: #fff;
}
.custom-pagination span.page-num {
margin-right: 10px;
padding: 0;
}
.custom-pagination span.dots {
padding: 0;
color: gainsboro;
}
.custom-pagination span.current {
background-color: #ff3c50;
color: #fff;
}