Php 基于类别的Wordpress自定义分页

Php 基于类别的Wordpress自定义分页,php,wordpress,pagination,Php,Wordpress,Pagination,这用于根据类别对博客文章进行分页。我在archive.php中导航帖子时遇到问题,当我导航到第2页等等,它会显示“找不到页面”。任何帮助都将不胜感激。提前感谢!:) archive.php <?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $current_cat_id = get_query_var('cat'); $custom_args = array(

这用于根据类别对博客文章进行分页。我在archive.php中导航帖子时遇到问题,当我导航到第2页等等,它会显示“找不到页面”。任何帮助都将不胜感激。提前感谢!:)

archive.php

<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$current_cat_id  = get_query_var('cat');

$custom_args = array(
                'post_type' => 'post',
                'posts_per_page' => 1,
                'cat'=>$current_cat_id,
                'paged' => $paged
            );

$custom_query = new WP_Query( $custom_args );


<?php if ( $custom_query->have_posts() ) : ?>

<!-- the loop -->
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
  <article class="loop">
    <h3><?php the_title(); ?></h3>
    <div class="content">
      <?php the_excerpt(); ?>
    </div>
  </article>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php
  if (function_exists(custom_pagination)) {
    custom_pagination($custom_query->max_num_pages,"",$paged);
  }
?>
<?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'       => __('&laquo;'),
'next_text'       => __('&raquo;'),
'type'            => 'plain',
'add_args'        => false,
'add_fragment'    => '');
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<div class='custom-pagination'><p class='pagination-label'> Page ".$paged." of ".$numpages."</p><div class='border'>&nbsp;</div><div class='holder'>";
  echo $paginate_links;
echo "</div><div class='border'>&nbsp;</div></div>";
}
}
?>

function.php

<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$current_cat_id  = get_query_var('cat');

$custom_args = array(
                'post_type' => 'post',
                'posts_per_page' => 1,
                'cat'=>$current_cat_id,
                'paged' => $paged
            );

$custom_query = new WP_Query( $custom_args );


<?php if ( $custom_query->have_posts() ) : ?>

<!-- the loop -->
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
  <article class="loop">
    <h3><?php the_title(); ?></h3>
    <div class="content">
      <?php the_excerpt(); ?>
    </div>
  </article>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php
  if (function_exists(custom_pagination)) {
    custom_pagination($custom_query->max_num_pages,"",$paged);
  }
?>
<?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'       => __('&laquo;'),
'next_text'       => __('&raquo;'),
'type'            => 'plain',
'add_args'        => false,
'add_fragment'    => '');
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<div class='custom-pagination'><p class='pagination-label'> Page ".$paged." of ".$numpages."</p><div class='border'>&nbsp;</div><div class='holder'>";
  echo $paginate_links;
echo "</div><div class='border'>&nbsp;</div></div>";
}
}
?>

显示
custom_pagination
函数..@SyedQarib我已经添加了上面的函数代码,顺便说一下:)我不知道这是否适用于您的情况,但在我的情况下,这是可行的,将您的基本分页参数更改为一个'base'=>stru replace($big,%#%',esc#url(get_pagenum link($big)))对于$big变量,只需使用$big=9999999初始化它;