分页不使用WP_QUERY(创建链接但不创建页面)

时间:2014-05-14 作者:tmyie

下面的循环获取相关类别中的所有帖子。它确实会生成分页URL,但它不会将我带到那里(它只是重定向回主页)。

有人知道为什么吗?

$paged = (get_query_var(\'page\')) ? get_query_var(\'page\') : 1;
$category_cat_args =
    array(
    \'category_name\' => $current_category,
    \'posts_per_page\' => 2,
    \'post_type\' => \'post\',
    \'post_status\' => \'publish\',
    \'orderby\' => \'date\',
    \'order\' => \'DESC\',
    \'&paged\' => $paged
);
$wp_query = new WP_Query( $category_cat_args );
?>
<div class="category-page">
    <div class="col68-2r">
        <h1 class="post-title">
        <?php echo $current_category; ?> news</h1>
        <?php
        if ( $wp_query->have_posts() ):
        while ( $wp_query->have_posts() ):
        $wp_query->the_post();
        $images = get_field( \'gallery\' );
        if ( $images ):
        ?>
        <div class="col33">
            <div class="img-ctnr">
                <a href="<?php the_permalink();?>">
                <img src="<?php  echo $images[0][\'url\'];?>" alt="example-image">
                <?php bottom_note(); ?>
                </a>
            </div>
        </div>
        <?php
        endif;
        endwhile;
        else: echo "There are no posts in this category";
        endif;
        ?>

        <?php wp_pagenavi( array( \'query\' => $wp_query ) ); ?>

        <div class="clear"></div>
        <?php if ( $wp_query->max_num_pages > 1 ) : ?>
        <a href="<?php  echo get_next_posts_page_link();  ?>" class="btn-ar"> more articles</a>
        <?php endif; ?>
    <?php wp_reset_postdata(); ?></div>

1 个回复
SO网友:Por

wp_pagenavi( array( \'query\' => $wp_query ) ); change to wp_pagenavi($wp_query);
我认为$wp\\u query是您定义的变量!这就是您需要插入的内容!有时,您需要根据您的自定义查询请求传递$wp\\u query->max\\u num\\u页面

结束