WordPress 子主题中的帖子分页 - 每个页面链接都显示相同的帖子

问题描述 投票:0回答:1

我正在做一个WordPress网站。我创建了一个子主题并编写/粘贴了一些代码。其中大部分都是有效的并且是标准代码。但关于分页的部分对我来说真的很难。我已经尝试了一整天,但无法让它发挥作用。我真的被困住了。无论您单击哪个页码,帖子列表下的页面链接都会返回相同的帖子,而不是在第一页上显示最新帖子,在第二页上显示较旧的帖子。

List of Posts - Navigation Always Shows The Same Posts

这是代码

<?php

//  Template Name: blog home         /

//  Jason Damisch's Category File    /

 ?>


<?php get_header(); ?>



<!--                  CONTENT                   -->
<!--                                            -->

<?php
   wp_reset_query();                     // necessary to reset query
   while ( have_posts() ) : the_post();
      the_content();
   endwhile;                             // End of the loop.
?>


<BR>
<HR>
<BR>

<!--                  POSTS                    -->
<!--                                           -->

<DIV STYLE="font-size:20px;">AHA HAPPENINGS</DIV>
<BR>

<?php
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $query = new WP_Query( array(
        'category_name' => 'Not Board Minutes',
        'posts_per_page' => 8,
        'paged' => $paged
    ) );
?>


<?php if ( $query->have_posts() ) : ?>

<!-- begin loop -->
<?php while ( $query->have_posts() ) : $query->the_post(); ?>

    <DIV STYLE="font-size:18px; color:#6EC1E4 !important;"><a href="<?php the_permalink(); ?>" title="Read"><?php the_title(); ?></a></DIV>

<!--    <?php  the_excerpt(); ?>   -->

<?php  foreach (get_the_category() as $category){   ?>
<?php  echo $category->cat_name;                    ?>
              &nbsp;   &nbsp;
<?php   }                                           ?>

    <BR>
    <?php echo get_the_date(); ?>

    <DIV STYLE="height:10px;"></DIV>

<?php endwhile; ?>
<!-- end loop -->




<!--             PAGINATION                    -->
<!--                                           -->

<div class="pagination">
    Pages of Happenings<BR>
    <?php
        echo paginate_links( array(
            'base'                => get_pagenum_link() . '%_%',
            'total'               => $query->max_num_pages,
            'current'             => max( 0, get_query_var( 'paged' ) ),
            'format'              => '?paged=%#%',
            'show_all'            => false,
            'type'                => 'plain',
            'end_size'            => 2,
            'mid_size'            => 10,
            'prev_next'           => true,
            'prev_text'           => __(' - Previous - '),
            'next_text'           => __(' - Next - '),
            'add_args'            => false,
            'add_fragment'        => '',
            'before_page_number'  =>  '<FONT SIZE=+2> &nbsp;&nbsp;[',
            'after_page_number'   =>  ']&nbsp;&nbsp; </FONT>',
        ) );
    ?>
</div>



<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

<?php wp_reset_postdata(); ?>



<?php get_footer(); ?>

有人可以帮助我并告诉我我做错了什么吗?

我希望每个页面链接都会根据帖子的年龄显示不同的帖子。

我尝试创建一个子主题,然后创建子主题的模板。然后我将代码放入模板 php 文件中。我在三个不同的子主题中尝试了这段代码,两个用于 Elementor,一个用于 Gutenberg。他们的行为都是一样的。所以,这似乎是我的错。我尝试了几个插件来显示帖子,但要么它们没有做任何事情,要么我必须为我需要的功能付费。我用谷歌搜索了一整天,试图找到解决方案。这是第二天,对我来说很艰难。我希望有人能帮忙。

杰森

wordpress pagination
1个回答
0
投票

面临的问题可能是由于基本 URL 请在您的 paginate_links() 函数中更新这些内容并尝试

'base'                => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
            'total'               => $query->max_num_pages,
            'current'             => max( 1, get_query_var('paged') ),
            'format'              => '?paged=%#%',
© www.soinside.com 2019 - 2024. All rights reserved.