如何在 Wordpress 自定义帖子类型查询中包含分页 [英] How to include pagination in a Wordpress Custom Post Type Query
本文介绍了如何在 Wordpress 自定义帖子类型查询中包含分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
<?php $the_query = new WP_Query('posts_per_page=30&post_type=phcl');?><?php while ($the_query -> have_posts()) : $the_query ->the_post();?><div class="col-xs-12 文件"><a href="<?php echo $file; ?>"class="file-title" target="_blank"><i class="fa fa-angle-right" aria-hidden="true"></i><?php echo get_the_title();?></a><div class="file-description"><?php the_content();?>
<?php endwhile;wp_reset_postdata();?>
我正在尝试使用 paginate_links
Wordpress 功能,但无论我把它放在哪里,我都无法让它工作.有人可以帮我解决这个问题吗?
解决方案
试试下面的代码:
$the_query = new WP_Query( array('posts_per_page'=>30,'post_type'=>'phcl','分页' =>get_query_var('paged') ?get_query_var('paged') : 1));?><?php while ($the_query -> have_posts()) : $the_query ->the_post();?><div class="col-xs-12 文件"><a href="<?php the_permalink(); ?>"class="file-title" target="_blank"><i class="fa fa-angle-right" aria-hidden="true"></i><?php echo get_the_title();?></a><div class="file-description"><?php the_content();?></div>
<?php终了;$big = 999999999;//需要一个不太可能的整数回声分页链接(数组('基础' =>str_replace( $big, '%#%', get_pagenum_link( $big ) ),'格式' =>'?paged=%#%','当前' =>max( 1, get_query_var('paged') ),'总计' =>$the_query->max_num_pages) );wp_reset_postdata();
I have the code below:
<?php $the_query = new WP_Query( 'posts_per_page=30&post_type=phcl' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="col-xs-12 file">
<a href="<?php echo $file; ?>" class="file-title" target="_blank">
<i class="fa fa-angle-right" aria-hidden="true"></i>
<?php echo get_the_title(); ?>
</a>
<div class="file-description">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
I am trying to use paginate_links
Wordpress function but no matter where I put it, I can't make it work. Can someone help me with this?
解决方案
Try the code below:
$the_query = new WP_Query( array('posts_per_page'=>30,
'post_type'=>'phcl',
'paged' => get_query_var('paged') ? get_query_var('paged') : 1)
);
?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="col-xs-12 file">
<a href="<?php the_permalink(); ?>" class="file-title" target="_blank">
<i class="fa fa-angle-right" aria-hidden="true"></i> <?php echo get_the_title(); ?>
</a>
<div class="file-description"><?php the_content(); ?></div>
</div>
<?php
endwhile;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
wp_reset_postdata();
这篇关于如何在 Wordpress 自定义帖子类型查询中包含分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!