这里似乎有无数的自定义查询分页问题,很高兴知道我不是唯一一个在这方面挣扎的人。我试着按照这些问题的答案来做,但到目前为止没有成功。
我有一个自定义的帖子类型,比如图库。每篇文章都有一个标题和一个包含图像的高级自定义字段库字段。当前在其中一篇文章上,它会在图像右侧显示前12篇文章的链接标题。这意味着你再也看不到12号了。我可以将12改为1来显示全部,但这个列表会持续一段时间。
希望添加分页,因此如果您在第一篇文章中,右侧列表下会显示“更多”,并将带您进入第13篇文章,右侧列表现在会显示13到24的链接标题。还有一个prev按钮和一个more按钮。Prev会返回到第一页并显示12个标题,更多内容会将您带到第25篇文章并显示25到36个标题,以此类推。
我尝试过以各种方式添加分页来实现这一点,但没有成功。有些问题我认为是对的,但有错误。分页是正确的方法吗,还是应该开发一个自定义if-else语句或类似语句来实现这一点?
<?php get_header(); ?>
<div id="main">
<div id="gallery-viewer">
<h3><?php the_title(); ?></h3>
<?php $images = get_field(\'gallery_images\');
if( $images ): ?>
<ul class="thumbs">
<?php foreach( $images as $image ): ?>
<li>
<a href="<?php echo $image[\'url\']; ?>">
<img src="<?php echo $image[\'sizes\'][\'gallery-landscape-thb\']; ?>" alt="<?php echo $image[\'alt\']; ?>" />
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<div class="places">
<ul class="plist selected first">
<?php $custom_query = new WP_Query(
array(
\'post_type\' => \'customers_gallery\',
\'posts_per_page\' => 12,
\'paged\' => $paged
)
);
if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
</ul>
// Add Pagination
</div>
</div>
</div><!-- /#main -->
<?php get_footer(); ?>