主页(WordPress)上的分页


Pagination on Home Page (WordPress)

我在尝试在我正在处理的网站的主页上进行分页时遇到问题。

"

较旧"和"较新"链接正确显示,它会更新 url 以反映页码,但翻阅页面时,帖子内容与第一页上的内容相同。 这是我正在使用的代码,当然是简化的:

if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); }
elseif ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); }
else { $paged = 1; }
$get_featured_posts = new WP_Query( array(
'posts_per_page'        => 9,
'post_type'             => 'post',
'ignore_sticky_posts'   => true,
'no_found_rows'         => true,
'paged'                 => $paged,
'offset'                => 5
 ) );
while( $get_featured_posts->have_posts() ):$get_featured_posts->the_post();
<h3 class="entry-title entry-added">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>">    <?php the_title(); ?></a>
</h3>
<p class="short_description"><?php echo short_description('...', 16); ?> </em></p>
<p class="read_more"><a href="<?php the_permalink(); ?>">Read More</a></p>
<?php
     endwhile;
?>
    <?php 
     // Reset Post Data
     wp_reset_query();
     ?>
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>

似乎无法弄清楚问题是什么,任何帮助将不胜感激。

尝试使用wp_reset_postdata();而不是wp_reset_query();,并且还更新了$paged的条件。

<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $get_featured_posts = new WP_Query( array(
    'posts_per_page'        => 9,
    'post_type'             => 'post',
    'ignore_sticky_posts'   => true,
    'no_found_rows'         => true,
    'paged'                 => $paged,
    'offset'                => 5
     ) );
    while( $get_featured_posts->have_posts() ):$get_featured_posts->the_post();
        <h3 class="entry-title entry-added">
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>">    <?php the_title(); ?></a>
        </h3>
        <p class="short_description"><?php echo short_description('...', 16); ?> </em></p>
        <p class="read_more"><a href="<?php the_permalink(); ?>">Read More</a></p>
        <?php
        endwhile;
        // Reset Post Data
        wp_reset_postdata();
        ?>
    <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
    <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
?>

请阅读此内容并在您的页面上插入分页代码并删除较新和较旧的链接

https://www.elegantthemes.com/blog/tips-tricks/how-to-add-pagination-to-wordpress

由于在WordPress交易所@milo,解决了问题所在。 事实证明,使用"偏移"和分页时有特殊的注意事项。 查看此链接了解更多详情。