0

Below is my code with the template. I have included pagination but not working.

<?php     
/*
Template Name: bydate
*/

?>

<?php get_header(); ?>

    <div id="primary" class="content-area clear">   
        <main id="main" class="site-main clear">
            <div id="recent-content" class="content-list">
                <?php 
                $args = array(
                    'posts_per_page' => 2,
                    'orderby' => 'endon',
                    'order' => 'ASC',
                    'meta_type' => 'DATE',
                    'meta_key' => 'endon',
                );
                $news = new WP_Query($args); 
                ?>

                <?php
                if ( have_posts() ) :       
                /* Start the Loop */
                while ($news->have_posts()) : $news->the_post();
                    get_template_part('template-parts/content', 'list');
                endwhile;
                else :
                    get_template_part( 'template-parts/content', 'none' );
                endif; 
                ?>

            </div><!-- #recent-content -->      
        </main><!-- .site-main -->

        <?php get_template_part( 'template-parts/pagination', '' ); ?>

    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

thank's

1 Answer 1

0

get_template_part( 'template-parts/pagination', '' ); is merely including the template-parts/pagination.php file from your theme. If you don't have that file then nothing will happen.

The correct way to add pagination is either the paginate_links() function, which will output links for each page number (see that link for the options for customising the output):

<?php echo paginate_links(); ?>

Or you could just output 'next page' and 'previous page' links with posts_nav_link():

<?php echo posts_nav_link(); ?>

If you want more control over where the next and previous links appear, you can output them separately with [previous_post_link()][3] and next_post_link().

<?php previous_post_link(); ?>
<?php next_post_link(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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