Wordpress分页链接重新加载页面

时间:2015-02-20 14:28:51

标签: php wordpress pagination wp-query

我正在尝试使用WP_Query构建分页存档侧边栏。由于在 single.php news.php 上使用相同的侧边栏,因此WP_Query使用的参数不同。

news.php 上,分页效果很好,但在 single.php 上,分页链接存在,并且具有正确的href值,但是只需在点击时重新加载页面,即超出第1页的任何内容都无法访问。

更新:如果这是相关的, single.php 会使用按AddToAny共享按钮社交(通过MailChimp)插件。我已经停用了这两个,但这并没有解决分页的问题。

任何人都可以为我阐明这一点吗?代码在这里:

    <aside>
<header>
    <h1 class="column-title">Archive</h1>
    <hr>
</header>
<div>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// remove first four posts if this is the news main page 
if ( ! is_single() ) {
    // Save first four posts
    $first_four = new WP_Query ('post_type=post&orderby=date&order=desc&posts_per_page=4');
    if ( $first_four->have_posts() ) : while ( $first_four->have_posts() ) : $first_four->the_post();
        $skipIDs[] = $post->ID;
    endwhile; endif;
    wp_reset_postdata();
    // Save all posts
    $args = array(
            'post_type' => 'post',
            'orderby' => 'date',
            'order' => 'DESC',
            'posts_per_page' => -1
    );
    $all_posts = new WP_Query($args);
    while ( $all_posts->have_posts() ) : $all_posts->the_post();
        // Skip first four posts and save rest
        if ( in_array($post->ID,$skipIDs) ) { continue; };
        $offset_array[] = $post->ID;
    endwhile;
    wp_reset_postdata();
    // Final arguments for WP_Query
    $args = array(
        'post__in' => $offset_array,
        'paged' => $paged,
        'posts_per_page' => 5
    );
} else {
    // Args for single.php
    $args = array(
            'post_type' => 'post',
            'orderby' => 'date',
            'order' => 'DESC',
            'posts_per_page' => 5,
            'paged' => $paged
    );
}
$article_archive = new WP_Query($args);
$max_pages = $article_archive->max_num_pages;
if( $article_archive->have_posts() ) : while( $article_archive->have_posts() ) : $article_archive->the_post(); 
$has_image = get_the_post_thumbnail($post->ID,'thumbnail'); ?>
    <article class="group">
        <a class="anchor-overlay" href="<?php the_permalink(); ?>"></a>
        <?php if( $has_image ) { echo $has_image; } else { echo "<img src='/wp-content/themes/DCSFC/images/news-calendar/news/no-image.jpg' alt='No image' />"; } ?>
        <div>
            <h3><?php the_title(); ?></h3>
            <time datetime="dd/MM/YYYY"><?php echo get_the_date(); ?></time>
        </div>
    </article>
<?php endwhile; endif; 
wp_reset_postdata();

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $max_pages
) );
?>

</div>

0 个答案:

没有答案