基于类别的Wordpress自定义分页

时间:2014-08-06 06:55:02

标签: 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(
                '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);
  }
?>
          

  

function.php

<?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>";
}
}
?>

0 个答案:

没有答案