自定义帖子类型的分页

时间:2014-10-16 13:22:44

标签: php wordpress pagination

我正在尝试为自定义帖子类型添加分页。我不知道代码有什么问题,但它不起作用。这是我到目前为止所做的:

    <?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( '&lt; <br/>Previous posts',$query) ?>
        </div>
        <div class="next-post">
            <?php previous_posts_link( '&gt; <br/>Next posts' ) ?>
        </div>
    </div>

知道我做错了吗?

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

    $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( '&lt; <br/>Previous posts',$query->max_num_pages ) ?>
    </div>
    <div class="next-post">
                <?php previous_posts_link( '&gt; <br/>Next posts' ) ?>
    </div>
</div>