[英]Pagination for custom post type
I'm trying to get pagination for a custom post type. 我正在尝试获取自定义帖子类型的分页。 I don't know what's wrong with the code but it doesn't work. 我不知道代码有什么问题,但是它不起作用。 This is what I have done so far: 到目前为止,这是我所做的:
<?php $query = new WP_Query( 'post_type=medios-link&order=DESC&posts_per_page=4' ); ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div><?php the_field('texto_adicional') ?></div>
<?php endwhile; ?>
<div class="nav-posts">
<div class="prev-post">
<?php next_posts_link( '< <br/>Previous posts',$query) ?>
</div>
<div class="next-post">
<?php previous_posts_link( '> <br/>Next posts' ) ?>
</div>
</div>
Any idea what i'm doing wrong? 知道我在做什么错吗?
Try following code: 尝试以下代码:
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query( 'post_type=product&order=DESC&posts_per_page=2&paged=' . $paged ); ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div><?php //the_field('texto_adicional')
the_title(); ?></div>
<?php endwhile;?>
<div class="nav-posts">
<div class="prev-post">
<?php next_posts_link( '< <br/>Previous posts',$query->max_num_pages ) ?>
</div>
<div class="next-post">
<?php previous_posts_link( '> <br/>Next posts' ) ?>
</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.