如何在Wordpress上添加前页和下一页的帖子


How to add prev page, and next page of posts on Wordpress?

我想在我的页脚添加上一页和下一页链接,所以我可以限制每页只有5篇文章。我不想要下一个帖子,和以前的帖子。我试着把它放入,并退出WP循环…但还是不行!我是WordPress的新手。我已经为single.php实现了下一篇文章和上一篇文章。我想有以前的帖子,下一篇文章将用于index.php和其他页面,如/categories/,但不是single.php.

  <footer id="home-footer">
            <?php posts_nav_link('','<','>'); ?>

            <div class="wrapper">
                        <p id="home-extra">You can find more articles at the <a href="/archive">archive</a>.</p>
            </div><!--end .wrapper -->
        <div class="footer-wrapper">
                <div class="projects">
                    <h1 id="projects-title">Projects</h1>
                        <ul class="footer-list">
                            <li><a href="http://dribbble.com/MatthewKosloski/projects/129666-iOS-Betas">iOS Betas</a></li>              
                        </ul>
                </div><!-- end .projects -->
                <div class="recent">
                        <h1 id="recent-title">Recent Posts</h1>

                            <ul class="footer-list">    
                                <?php
                                    $args = array( 'numberposts' => '5' );
                                    $recent_posts = wp_get_recent_posts( $args );
                                    foreach( $recent_posts as $recent ){
                                        echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li> ';
                                    }
                                ?>
                            </ul>
                </div><!-- end .recent -->
        <div id="dribbble"><h1 id="recent-title">What i'm working on</h1></div>
        <script type="text/javascript" src = "https://halfcourtshot.googlecode.com/svn/tags/1/js/half-court-shot.jsapp.mh.min.js"></script>
        <script type="text/javascript">var hcs = new HalfCourtShot({ jersey: "matthewkosloski", shots: 3, goal: 'dribbble' });</script>                         
        </div><!-- end .footer-wrapper -->
            <div class="note-wrapper">
                <p id="note">&copy; 2013 Matthew Kosloski</p>
            </div><!-- end .note-wrapper-->
    </footer>

在你的admin设置> Reading (wp-admin/options-reading.php)将每页的帖子数改为5

和链接,你写错了,按照法典

试试这个

<?php posts_nav_link('','<','>'); ?>

更新:

你可以添加if/else语句来显示单个或索引的不同

<?php if(is_single()) { // single-view navigation ?>
    <?php $posts = query_posts($query_string); if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php previous_post_link('%link', '<'); ?>  | <?php next_post_link('%link', '>'); ?>
    <?php endwhile; endif; ?>
<?php } else { // archive view navigation ?>
        <?php posts_nav_link('','<','>'); ?>
<?php } ?>

查看更多帮助