0

I am working on a site as an intern. The site that i am working with is called www.erikzandstra.nl (its dutch) Currently, I am working on the blog page. On the blog page, I wanted to add some php code to get navigation buttons to go to the next and previous posts. I searched through internet and could not find any code that worked. I cant program with php but i kinda do understand it. What i need is some (php)code that makes 2 buttons to go to previous and next posts. Here is the code i currently use:

                <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 -->
0

I think you should use wp_link_pages function, it's was built for that purpose.

$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 );

You can refer to the codex page to learn more how to use each parameter : https://codex.wordpress.org/Function_Reference/wp_link_pages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.