繁体   English   中英

如何在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>

在您的管理设置>阅读(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 } ?>

在这里查看更多帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM