Wordpress页面导航错误400自定义模板

时间:2017-03-13 05:40:54

标签: php html wordpress page-numbering

我有一个自定义模板category.php,我添加了以下代码用于分页,但它不起作用。当我单击下一页按钮时,它会转到404错误页面,链接如下所示:../ mythemedir / cat = x& page = 1& paged = 2 404 error page after click the next button and link: mythemedir/cat=x&page=1&paged=2 但是当我在地址栏中手动输入地址时:.. / mythemedir / cat = x& page = 2一切正常,但“上一页”按钮的链接是mythemedir / cat = x& page = 2

After type the adress manually i got a my second page but previous button didn't work我应该怎么做才能解决它?

这是我页面上的代码:

 <?php global $paged;
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query = new WP_Query (array(
   'posts_per_page' => 3,
     'cat'      => '2, 30',
        'lang'           => pll_current_language(),
     'paged' =>  $paged
));

while($query->have_posts()) : 
   $query->the_post();  

  ?>

// Loop content

<?php endwhile ?>

这是我的导航页面上的代码:

<?php if (function_exists("pagination")) {
    pagination($query->max_num_pages,"",$paged);
        } ?>

这是我的functions.php文件中的代码:

function pagination($pages = '', $range = 4)
{  
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
         echo "</div>\n";
     }
}

0 个答案:

没有答案