自定义页面实现翻页
如果您已经非常了解您的目标受众,并且知道如何直接定位他们,那么应用程序可以满足您的需求,但如果您的受众范围可能很广,那么网站可能是最适合的。
<?php
$args = array(
'post_type' => 'post', // Replace 'books' with your custom post type slug.
'posts_per_page' => 1, // Set the number of posts to display per page.
'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
);
$custom_query = new WP_Query( $args );
$total_pages = $custom_query->max_num_pages;
$current_page = max( 1, get_query_var( 'paged' ) );
?>
<main id="primary" class="site-main">
<?php
if ( $custom_query->have_posts() ) {
while ( $custom_query->have_posts() ) {
$custom_query->the_post();
?>
<article>
<h2><?php the_title(); ?></h2>
<!-- Display other post fields or content here -->
</article>
<?php
}
} else {
?>
<p>No books found.</p>
<?php } ?>
<div class="pagination">
<?php
echo paginate_links(
array(
'base' => get_pagenum_link( 1 ) . '%_%',
'format' => '/page/%#%', // Change to match your URL structure if needed.
'current' => $current_page,
'total' => $total_pages,
)
);
?>
</div>
</main>