简体   繁体   中英

How do have prev and next links on custom querys wordpress?

I have a custom template I am using for my page and in that custom template I get the_content() then I use a custom query. I want to be able to only get 6 of my posts then be able to go to prev and next to see the rest of the posts.

Here is some of my code:

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <div class="entry-content">

                <div id="the_content">                          
                    <?php the_content(); ?>
                </div>
                <?php 

                $args = array('numberposts'=> 6,
                                'post_type'=>'project'
                                ); 
                $posts = get_posts( $args );

                    if($posts){

                        foreach( $posts as $post ) :    setup_postdata($post);

                           //do stuff 

                             wp_reset_postdata();
                    endforeach;
                 endwhile;
               </div>
            </article>

?>

Try this

<?php posts_nav_link();

Reference: http://codex.wordpress.org/Next_and_Previous_Links

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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