【问题标题】:Pagination problem on the homepage in wordpresswordpress首页的分页问题
【发布时间】:2021-07-31 06:39:30
【问题描述】:

我正在使用以下代码进行主页分页。问题是每当我尝试在页面之间切换时帖子都没有改变,但我可以看到永久链接中的分页变化。有人可以帮我解决这个问题吗?

<?php
    $ourCurrentPage = get_query_var('page') ? get_query_var('page') : 1;
        $args = array(
          'post_type'=> 'post',
          'order'    => 'DESC',
          'posts_per_page' => 4,
          'page' => $ourCurrentPage,

        );              
        $my_query = new WP_Query( $args );
        if($my_query->have_posts()) : while ($my_query->have_posts() ) : $my_query->the_post(); ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        
                    <div class="post-content" data-aos="zoom-in" data-aos-delay="200">
                       -------------
                       -------------
                </div>
           
        
</article><!-- #post-## -->
        <?php endwhile; 
echo paginate_links(array(
'total' => $my_query->max_num_pages
));
?>

【问题讨论】:

    标签: php wordpress pagination website-homepage


    【解决方案1】:

    这是“分页”而不是“页面”

    $args = array(
            'post_type'=> 'post',
            'order'    => 'DESC',
            'posts_per_page' => 4,
            'paged' => $ourCurrentPage,
        );
    

    【讨论】:

    • 感谢您的回复。现在,每当我单击页面按钮时,帖子都会动态变化,但按钮中没有任何活动,因为即使我切换到第 2、3 等页面,活动链接也始终指向第 1 页。
    猜你喜欢
    • 1970-01-01
    • 2017-11-09
    • 2014-09-06
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 2012-04-16
    • 1970-01-01
    相关资源
    最近更新 更多