index.php navigation

时间:2016-10-18 作者:Naaman

我在一家网站实习。我正在使用的网站名为www.erikzandstra。nl(荷兰语)目前,我正在博客页面上工作。在博客页面上,我想添加一些php代码来获得导航按钮,以便转到下一篇和上一篇文章。我在互联网上搜索,没有找到任何有效的代码。我不能用php编程,但我有点理解它。我需要的是一些(php)代码,它可以生成两个按钮来转到上一篇和下一篇文章。以下是我当前使用的代码:

                <article id="post-<?php the_ID(); ?>" <?php post_class(\'clearfix\'); ?> role="article">

                    <header>

                        <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail( \'wpbs-featured\' ); ?></a>

                        <div class="page-header"><h1 class="h2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1></div>

                        <p class="meta"><?php _e("Posted", "wpbootstrap"); ?> <time datetime="<?php echo the_time(\'Y-m-j\'); ?>" pubdate><?php echo get_the_date(\'F jS, Y\', \'\',\'\', FALSE); ?></time> <?php _e("by", "wpbootstrap"); ?> <?php the_author_posts_link(); ?> <span class="amp">&</span> <?php _e("filed under", "wpbootstrap"); ?> <?php the_category(\', \'); ?>.</p>

                    </header> <!-- end article header -->

                    <section class="post_content clearfix">
                        <?php the_content( __("Read more &raquo;","wpbootstrap") ); ?>
                    </section> <!-- end article section -->

                    <footer>

                        <p class="tags"><?php the_tags(\'<span class="tags-title">\' . __("Tags","wpbootstrap") . \':</span> \', \' \', \'\'); ?></p>

                    </footer> <!-- end article footer -->

                </article> <!-- end article -->

                <?php endwhile; ?>  

                <?php if (function_exists(\'wp_bootstrap_page_navi\')) { // if expirimental feature is active ?>

                    <?php wp_bootstrap_page_navi(); // use the page navi function ?>

                <?php } else { // if it is disabled, display regular wp prev & next links ?>
                    <nav class="wp-prev-next">
                        <ul class="pager">
                            <?php next_post_link(\'%link\', \'Next post >\'); ?>

                        </ul>
                    </nav>
                <?php } ?>      

                <?php else : ?>

                <article id="post-not-found">
                    <header>
                        <h1><?php _e("Not Found", "wpbootstrap"); ?></h1>
                    </header>
                    <section class="post_content">
                        <p><?php _e("Sorry, but the requested resource was not found on this site.", "wpbootstrap"); ?></p>
                    </section>
                    <footer>
                    </footer>
                </article>

                <?php endif; ?>

            </div> <!-- end #main -->

            <?php get_sidebar(); // sidebar 1 ?>

        </div> <!-- end #content -->

1 个回复
SO网友:Amine Faiz

我认为您应该使用wp\\u link\\u pages函数,它就是为此而构建的。

$defaults = array(
    \'before\'           => \'<p>\' . __( \'Pages:\' ),
    \'after\'            => \'</p>\',
    \'link_before\'      => \'\',
    \'link_after\'       => \'\',
    \'next_or_number\'   => \'number\',
    \'separator\'        => \' \',
    \'nextpagelink\'     => __( \'Next page\' ),
    \'previouspagelink\' => __( \'Previous page\' ),
    \'pagelink\'         => \'%\',
    \'echo\'             => 1
);

    wp_link_pages( $defaults );
您可以参考codex页面了解如何使用每个参数的更多信息:https://codex.wordpress.org/Function_Reference/wp_link_pages