dshu1235 2017-03-13 05:40
浏览 48

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

I have a custom template category.php and i have added following code for pagination but it does not work. When I click the next page button it goes to 404 error page and link looks like this: ../mythemedir/cat=x&page=1&paged=2 404 error page after click the next button and link: mythemedir/cat=x&page=1&paged=2 But when i type the address manually in the address bar: ../mythemedir/cat=x&page=2 everything is ok but the link of "Previous" button is mythemedir/cat=x&page=2

After type the adress manually i got a my second page but previous button didn't work What should I do for fix it?

This is my code on my page:

 <?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 ?>

This is my code on my page for navigation:

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

This is my code in my functions.php file:

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>
";
     }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch