由于某些原因,分页按钮未显示-任何帮助将不胜感激。另外,有8个帖子显示的代码中不像10个那样。
<?php get_header(); ?>
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<div class="container-fluid p-0 pagewrap pagehead position-relative d-table" id="recent-projects">
<div class="container pageintro">
<div class="row">
<div class="col-12">
<h1>Recent Projects</h1>
<p>View our recent project case studies below</p>
</div>
</div>
</div>
</div>
<div class="container-fluid pt-5 pb-2">
<div class="container">
<div class="row">
<?php $catquery = new WP_Query( 'post_type=>projects&posts_per_page=10'.'&paged='.$paged );?>
<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<div class="col-md-6">
<div class="grid">
<figure class="effect-oscar">
<?php the_post_thumbnail('large', array('style' => 'width: 100%; height: 200px; margin: 0px auto 15px auto;')) ?>
<figcaption>
<div class="m-auto">
<h2><span class="post-date"><?php echo get_the_date(); ?></span><?php the_title(); ?></h2>
<p><span><?php the_excerpt(); ?></span></p>
<a href="<?php the_permalink(); ?>">Read Post</a>
</figcaption>
</figure>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<div class="pagination-nav text-center m-auto d-block p-4 mx-auto my-4">
<?php echo paginate_links( array(
'prev_text' => '<span>Previous Page</span>',
'next_text' => '<span>Next Page</span>'
)); ?>
</div>
</div>
<?php get_footer(); ?>
这也是自定义帖子类型页面
答案 0 :(得分:0)
首先,您的WP_Query args设置不正确。应该是:
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = [
'post_type' => 'projects',
'posts_per_page' => 10,
'paged' => $paged
];
$catquery = new WP_Query( $args );
?>
这是大多数开发人员首选的方法。但是,如果您想知道自己的错误是什么...您可以使用箭头符号设置帖子类型,但只能使用等号。: post_type = projects
接下来,您的分页不知道您的自定义帖子类型。您必须明确设置它:
<?php
// Need a big base number:
$big = 999999999;
// Pagination
paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $catquery->max_num_pages,
'prev_text' => '<span>Previous Page</span>',
'next_text' => '<span>Next Page</span>'
) );