Wordpress 如何将分页添加到自定义页面模板

Wordpress 如何将分页添加到自定义页面模板,wordpress,pagination,Wordpress,Pagination,我刚刚创建了一个新的自定义页面模板,只调用了两篇文章。 我怎样才能添加分页,这样我就可以链接到至少两篇最新的文章 我尝试了此代码,但不起作用: <?php $paged = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1; query_posts( array ( 'post_type' => 'post', 'category_n

我刚刚创建了一个新的自定义页面模板,只调用了两篇文章。 我怎样才能添加分页,这样我就可以链接到至少两篇最新的文章


我尝试了此代码,但不起作用:

<?php
    $paged = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
    query_posts( 
        array ( 
            'post_type' => 'post', 
            'category_name' => 'news', 
            'category' => 1,
            'posts_per_page' => 2,
            'paged' => $paged ) 
        );      
        // The Loop
        while ( have_posts() ) : the_post();?>
            <div class="news-page-content-wrapper">
                <div class="news-page-content">
                    <h1><a class="read-more"href="<?php the_permalink(); ?>"><?php the_title();?></a></h1>
                    <figure><?php the_post_thumbnail(); ?></figure>
                    <p><?php echo get_the_excerpt();?></p>
                    <a href="<?php the_permalink(); ?>">Read More&raquo</a>
                </div>
            </div>   
        <?endwhile; 
        // Reset Query
        wp_reset_query();
    ?>

有什么帮助吗?

因为您使用的是“循环”,所以应该使用内置函数来显示分页

以下是一些示例:

我已更新您的示例代码以显示默认分页:

<?php
    $paged = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
    query_posts( 
        array ( 
            'post_type' => 'post', 
            'category_name' => 'news', 
            'posts_per_page' => 2,
            'paged' => $paged ) 
        );      
        // The Loop
        while ( have_posts() ) : the_post(); ?>
            <div class="news-page-content-wrapper">
                <div class="news-page-content">
                    <h1><a class="read-more"href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                    <figure><?php the_post_thumbnail(); ?></figure>
                    <p><?php echo get_the_excerpt(); ?></p>
                    <a href="<?php the_permalink(); ?>">Read More&raquo; </a>
                </div>
            </div>   
        <?php endwhile; 

        the_post_navigation();
        // Reset Query
        wp_reset_query();
    ?>


我尝试了这段代码,但效果不太好@SidneySousa上述工作,我刚刚测试了我的一个测试网站。不知道到底是什么不同,但我只是复制和粘贴的代码从抄本上的链接,你发送它的工作。这是php为你!我建议的一件事是确保在
建议被完全接受后始终有一个空格。保持一些好习惯总是好的。感谢您的支持。