奇怪的分页行为给出白页

时间:2014-04-23 21:16:37

标签: php wordpress pagination

我正在使用WordPress分页。我已经在我的其他页面上使用了这个代码并且它在那里工作正常,但是当我尝试转到下一个分页链接时,在此页面上“调度”它会给出白页。

我重置了永久链接设置,因为这是我在互联网上找到的唯一解决方案。仍然没有同样的问题。

在数据库中,他们在此自定义帖子类型下共有9条记录,因此通过分页,每页将有3条记录。

分页代码

<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
    'post_type' => 'schedules', 
    'posts_per_page' => 3,
    'post_status' => 'publish',
    'paged' => $paged
);
query_posts($args);
if ( have_posts() ) :
    while ( have_posts() ) : the_post();
        $schedules_vessel = get_field('schedules_vessel');
        $schedules_voyage = get_field('schedules_voyage');
        $schedules_port = get_field('schedules_port');
        $schedules_country = get_field('schedules_country');
        $schedules_arrival = get_field('schedules_arrival');
        $schedules_departure = get_field('schedules_departure');
        $date = DateTime::createFromFormat('d/m/Y h:i A', $schedules_arrival);
        $schedules_arrival_date = $date->format('d M Y');
        $schedules_arrival_time = $date->format('G:i');
        $date = DateTime::createFromFormat('d/m/Y h:i A', $schedules_departure);
        $schedules_departure_date = $date->format('d M Y');
        $schedules_departure_time = $date->format('G:i');
?>          
<?php endwhile; endif; ?>
<?php require_once( get_template_directory() . "/snippets/pagination.php"); ?>                    

在pagination.php

<?php
    global $wp_query;
    $temp = "";
    $big = 999999999;
    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'prev_text' => 'Previous',
        'next_text' => 'Next',
        'type' => 'list'
    ));
?>
<?php 
$wp_query = null; 
$wp_query = $temp;
wp_reset_query();
?>

1 个答案:

答案 0 :(得分:0)

我讨厌回答我自己的问题,但是我找到了解决方案。问题出在自定义帖子类型slug&#34; schedule&#34;与页面名称相同的slug&#34; schedule&#34;我认为这是相互矛盾的,我不认为它应该反正。

相关问题