【问题标题】:Strange pagination behavior giving white page奇怪的分页行为给白页
【发布时间】:2014-04-23 21:16:37
【问题描述】:

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

我已重置永久链接设置,因为这是我在 Internet 上找到的唯一解决方案。还是没有同样的问题。

在数据库中,此自定义帖子类型下共有 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();
?>

【问题讨论】:

    标签: php wordpress pagination


    【解决方案1】:

    我讨厌回答自己的问题,但我找到了解决方案。问题在于自定义帖子类型 slug“schedules”与页面名称“schedules”具有相同的 slug,我认为这是冲突的,我认为它不应该,但无论如何。

    【讨论】:

      猜你喜欢
      • 2015-09-04
      • 2015-05-13
      • 2017-12-07
      • 1970-01-01
      • 2013-08-19
      • 2013-11-12
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多