首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用"wp-query“对Wordpress进行分页

使用"wp-query“对Wordpress进行分页
EN

Stack Overflow用户
提问于 2014-10-10 01:40:59
回答 1查看 79关注 0票数 0

嘿,我正在使用自定义post类型在自定义page.php中运行查询循环。我会为它分页,以便我可以有一个特定的数量,每页。我想知道是否有人能帮我。我在下面添加了代码:

代码语言:javascript
复制
<?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; ?>

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-10 01:50:23

正如wordpress.org文档所说的,问题是:

分页将无法正常工作,除非您适当地设置了“分页”查询var :添加分页参数

使用示例:

代码语言:javascript
复制
<?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
?>

此外,如果您对巫术指南有更多的疑问,可以检查它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26290652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档