简体   繁体   English

使用“ wp-query”与Wordpress分页

[英]Pagination with Wordpress using “wp-query”

Hey all i'm running a query loop in a custom page.php using a custom post type. 嘿,我正在使用自定义帖子类型在自定义page.php运行查询循环。 I would for it to paginated so i could have a specific amount of post per page. 我希望它能分页,这样我每页可以有特定数量的帖子。 I was wondering if someone could help me out. 我想知道是否有人可以帮助我。 I have added my code below: 我在下面添加了我的代码:

<?php query_posts( array(
     'post_type' => array( 'POSTTYPE' ),
      'showposts' => -1 )
     ); ?>

            <?php while ( have_posts() ) : the_post(); ?>


         <div class="">
         <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
         <?php the_post_thumbnail( 'thumbnail' , array('class' => 'aligncenter project_post_thumbnail') ); ?> 
         <a href="<?php the_permalink();?>">View </a>
         </div>


<?php endwhile; ?>

Thanks! 谢谢!

The problem as wordpress.org documentation says: wordpress.org文档所述的问题:

Pagination won't work correctly, unless you set the 'paged' query var appropriately: adding the paged parameter 分页将无法正常工作,除非您适当地设置了“ paged”查询变量:添加paged参数

Example of usage: 用法示例:

<?php
 $args = array(
               'cat' => '5',
               'post_type' => 'POSTTYPE',
               'posts_per_page' => 6,
               'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
               );

query_posts($args);
while (have_posts()) : the_post();
 /* Do whatever you want to do for every page... */
?>
     <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
     <?php the_post_thumbnail( 'thumbnail' , array('class' => 'aligncenter project_post_thumbnail') ); ?> 
     <a href="<?php the_permalink();?>">View </a>
<?php
    endwhile;
?>
<div class="navigation">
    <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
    <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
</div>
<?php
    wp_reset_query();  // Restore global post data
?>

Also you can check rvoodoo guide if you have more questions about it. 如果您还有其他疑问,也可以查看rvoodoo指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM