0

I make a page template, but when I click the pagination it doesn't work.

<?php

/**
 * Template Name: ashole
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 * @package Dan
 */

get_header(); ?>

<div id="primary" class="content-area">

<main id="main" class="site-main" role="main">

<?php query_posts("showposts=2") ?>

<?php if ( have_posts() ) : ?>

<?php while ( have_posts() ) : the_post(); ?>

<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><br />

<?php echo get_the_category_list(', '); ?>

<?php the_time('d/m/Y g:i:s A'); ?><br />

<img src="<?php $img=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large'); echo $img[0]; ?>"/><br />

<?php the_excerpt(); ?> <br />

<?php endwhile; 

/* Previous/next page navigation. */

  the_posts_pagination( array(

     'prev_text'         => '<span class="fas fa-angle-double-left" aria-hidden="true"></span> ' . __( 'Previous page', 'dan' ),

     'next_text'         => __( 'Next page', 'dan' ) . ' <span class="fas fa-angle-double-right" aria-hidden="true"></span>',

     'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'dan' ) . '</span>',

  ) );


  ?>

<?php endif; ?>

   </main><!-- #main -->

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

<?php

get_sidebar();

get_footer();
1
  • edit your question and add your code, questions should not rely on external links.
    – Milo
    Commented Aug 3, 2018 at 17:54

1 Answer 1

0

Because you override global WP_Query with your own query_posts and you ignore page in there - all you set is showposts (which is deprecated and from wp 2.1 you should use posts_per_page instead).

But to be honest, you shouldn’t use query_posts either (especially in this case).

So how to do this? Use pre_get_posts filter to modify global query according to your needs.

1
  • thank you for your help, but I still don't understand, can you improve and add what you explain to my code please, thank's
    – Anes
    Commented Aug 4, 2018 at 7:58

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.