Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wordpress分页在本地主机服务器中不工作_Wordpress - Fatal编程技术网

wordpress分页在本地主机服务器中不工作

wordpress分页在本地主机服务器中不工作,wordpress,Wordpress,我已经使用wordpress下面的代码在本地主机模板中分页,但不知道为什么它不工作。它很好地显示了所有的页码,但任何页码我都会单击它唯一显示的第一页 global $wp_query; $total_pages = $wp_query->max_num_pages; if ($total_pages > 1){ $current_page = max(1, get_query_var('paged')); echo paginate_links(array(

我已经使用wordpress下面的代码在本地主机模板中分页,但不知道为什么它不工作。它很好地显示了所有的页码,但任何页码我都会单击它唯一显示的第一页

global $wp_query;  
$total_pages = $wp_query->max_num_pages;  
if ($total_pages > 1){  
$current_page = max(1, get_query_var('paged'));  
echo paginate_links(array(  
  'base' => get_pagenum_link(1) . '%_%',  
  'format' => '/page/%#%',  
  'current' => $current_page,  
  'total' => $total_pages,  
));  
}
我的永久链接设置是:

localhost/my blog/sample post/

和查询帖子:

$args=数组('post\u type'=>'post','posts\u per\u page'=>2)

任何人都可以告诉我下一步如何进行分页。

max\u num\u pages;
  <global $wp_query;
$total = $wp_query->max_num_pages;
// only bother with the rest if we have more than 1 page!
if ( $total > 1 )  {
     // get the current page
     if ( !$current_page = get_query_var('paged') )
          $current_page = 1;
     // structure of "format" depends on whether we're using pretty permalinks
     $format = empty( get_option('permalink_structure') ) ? '&page=%#%' : 'page/%#%/';
     echo paginate_links(array(
          'base' => get_pagenum_link(1) . '%_%',
          'format' => $format,
          'current' => $current_page,
          'total' => $total,
          'mid_size' => 4,
          'type' => 'list'
     ));
}
//只有当我们有超过1页的时候,才需要处理剩下的! 如果($total>1){ //获取当前页面 if(!$current\u page=get\u query\u var('paged')) $current_page=1; //“格式”的结构取决于我们是否使用了相当长的永久链接 $format=empty(get_选项('permalink_结构')?'&page=%#%':'page/%#%/'; 回显分页链接(数组( 'base'=>get_pagenum_link(1)。'%\%', 'format'=>$format, “当前”=>$current\u页面, “总计”=>$total, “中等尺寸”=>4, '类型'=>'列表' )); }
请根据要求设置参数,并参考此链接

如果你面临问题,请告诉我


感谢并问候

这适用于WP\U查询。你可以试试:

global $wp_query;
$big = 999999999; // Need an unlikely integer
echo paginate_links( array( 'base'    => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                            'format'  => '?paged=%#%',
                            'current' => max( 1, get_query_var( 'paged' ) ),
                            'total'   => $wp_query->max_num_pages,
                            'end_size'=> 1,
                            'mid_size'=> 10 ) );

Settings->Readings
set
Blog pages中最多显示每个页面中要显示的帖子数量,在
Settings->Discussion中设置分页行为

我通过使用纯PHP读取URL参数解决了相同的问题,而不是使用get_query_var('paged'),只需使用以下命令:

$_GET['paged']

谢谢你的回复。。有同样的问题。尽管我的url显示>/localhost/my blog/page/2,但仍显示第一页