像这样的事情应该行得通。我在注释中对代码添加了一些解释:
<div class="title text-center">
<h1><strong><?php the_title(); ?></strong></h1>
<img src="<?php echo get_template_directory_uri(); ?>/images/title.png" title="title-line" alt="title-line">
</div>
<div id="no-more-tables" class="legel">
<?php the_content(); ?>
</div>
<?php
// Get the page from the url e.g. domain.com/articles?paged=2 would be page 2.
$paged = ( get_query_var( \'paged\' ) ) ? absint( get_query_var( \'paged\' ) ) : 1;
// Use WP_Query instead of get_posts() - it is much better for proper queries.
// get_posts() should only really be used for getting a few posts (e.g. related
// articles)
$category_posts = WP_Query(
array(
\'posts_per_page\' => 5,
\'category\' => \'13\',
\'paged\' => $paged,
)
);
?>
<?php if ( $category_posts->have_posts() ) : ?>
<?php while ( $category_posts->have_posts() ) : $category_posts->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php
// Set $big as a massive integer
$big = 999999999;
// Echo the pagination (E.g. Prev 1 2 3 3 4 5 Next)
echo paginate_links(
array(
\'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
\'format\' => \'?paged=%#%\', // Matches your query above
\'current\' => max( 1, get_query_var( \'paged\' ) ),
\'total\' => $category_posts->max_num_pages,
)
);
?>
<?php wp_reset_postdata(); // This must be run after every WP_Query ?>
<?php else : ?>
No Posts
<?php endif; ?>