嘿,我正在使用自定义post类型在自定义page.php中运行查询循环。我会为它分页,以便我可以有一个特定的数量,每页。我想知道是否有人能帮我。我在下面添加了代码:
<?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; ?>谢谢!
发布于 2014-10-10 01:50:23
正如wordpress.org文档所说的,问题是:
分页将无法正常工作,除非您适当地设置了“分页”查询var :添加分页参数
使用示例:
<?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('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
<?php
wp_reset_query(); // Restore global post data
?>此外,如果您对巫术指南有更多的疑问,可以检查它。
https://stackoverflow.com/questions/26290652
复制相似问题